Code

syscollectord: Include extra version information in startup/shutdown messages.
[sysdb.git] / src / liboconfig / utils.c
1 /**
2  * oconfig - src/utils.h
3  * Copyright (C) 2012 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  */
19 #ifndef OCONFIG_UTILS_H
20 #define OCONFIG_UTILS_H 1
22 #include "liboconfig/oconfig.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 int
29 oconfig_get_string(oconfig_item_t *ci, char **value)
30 {
31         if (! ci)
32                 return -1;
34         if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
35                 return -1;
37         if (value)
38                 *value = ci->values[0].value.string;
39         return 0;
40 } /* oconfig_get_string */
42 int
43 oconfig_get_number(oconfig_item_t *ci, double *value)
44 {
45         if (! ci)
46                 return -1;
48         if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
49                 return -1;
51         if (value)
52                 *value = ci->values[0].value.number;
53         return 0;
54 } /* oconfig_get_number */
56 int
57 oconfig_get_boolean(oconfig_item_t *ci, _Bool *value)
58 {
59         if (! ci)
60                 return -1;
62         if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
63                 return -1;
65         if (value)
66                 *value = ci->values[0].value.boolean != 0;
67         return 0;
68 } /* oconfig_get_boolean */
70 #ifdef __cplusplus
71 } /* extern "C" */
72 #endif
74 #endif /* OCONFIG_UTILS_H */
76 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */