conf_cookie valid only for Linux.
[monky] / src / conf_cookie.c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include "defconfig.h"
5
6 ssize_t conf_read(void *cookie, char *buf, size_t size)
7 {
8         static int col = 0, row = 0;
9         size_t i = 0;
10         const char *conf[] = defconfig;
11
12         (void)cookie;
13
14         while (i < size) {
15                 if (!(conf[row]))               /* end of rows */
16                         break;
17                 if (!(conf[row][col])) {        /* end of line */
18                         row++;
19                         col = 0;
20                         continue;
21                 }
22                 buf[i++] = conf[row][col++];
23         }
24         return i;
25 }
26
27 #if defined(__linux__)
28 cookie_io_functions_t conf_cookie = {
29         .read = &conf_read,
30         .write = NULL,
31         .seek = NULL,
32         .close = NULL,
33 };
34 #endif