Add vim modelines.
[monky] / src / conf_cookie.c
1 /* Conky, a system monitor, based on torsmo
2  *
3  * Please see COPYING for details
4  *
5  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
6  *      (see AUTHORS)
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  * 
21  * vim: ts=4 sw=4 noet ai cindent syntax=c
22  *
23  */
24
25 #define _GNU_SOURCE
26 #include "config.h"
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include "defconfig.h"
30
31 #if defined(HAVE_FOPENCOOKIE)
32 #define COOKIE_LEN_T    size_t
33 #define COOKIE_RET_T    ssize_t
34 #else
35 #define COOKIE_LEN_T    int
36 #define COOKIE_RET_T    int
37 #endif
38
39 static COOKIE_RET_T
40 conf_read(void *cookie, char *buf, COOKIE_LEN_T size)
41 {
42         static int col = 0, row = 0;
43         COOKIE_LEN_T i = 0;
44         const char *conf[] = defconfig;
45
46         (void)cookie;
47
48         while (i < size) {
49                 if (!(conf[row]))               /* end of rows */
50                         break;
51                 if (!(conf[row][col])) {        /* end of line */
52                         row++;
53                         col = 0;
54                         continue;
55                 }
56                 buf[i++] = conf[row][col++];
57         }
58         return i;
59 }
60
61 #if defined(HAVE_FOPENCOOKIE)
62 static cookie_io_functions_t conf_cookie = {
63         .read = &conf_read,
64         .write = NULL,
65         .seek = NULL,
66         .close = NULL,
67 };
68 FILE *conf_cookie_open(void)
69 {
70         return fopencookie(NULL, "r", conf_cookie);
71 }
72 #elif defined(HAVE_FUNOPEN)
73 FILE *conf_cookie_open(void)
74 {
75         return funopen(NULL, &conf_read, NULL, NULL, NULL);
76 }
77 #else
78 FILE *conf_cookie_open(void) { return NULL; }
79 #endif