]> git.pld-linux.org Git - projects/rc-scripts.git/blame - src/shvar.h
netfs: respect VSERVER_ISOLATION_NET here as well
[projects/rc-scripts.git] / src / shvar.h
CommitLineData
458f14b7
AM
1/*
2 * shvar.h
3 *
4 * Interface for non-destructively reading/writing files containing
5 * only shell variable declarations and full-line comments.
6 *
7 * Includes explicit inheritance mechanism intended for use with
8 * Red Hat Linux ifcfg-* files. There is no protection against
9 * inheritance loops; they will generally cause stack overflows.
10 * Furthermore, they are only intended for one level of inheritance;
11 * the value setting algorithm assumes this.
12 *
13 * Copyright 1999 Red Hat, Inc.
14 *
15 * This is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 */
30#ifndef _SHVAR_H
31#define _SHVAR_H
32
33#include <glib.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif /* __cplusplus */
38
39typedef struct _shvarFile shvarFile;
40struct _shvarFile {
41 char *fileName; /* read-only */
42 int fd; /* read-only */
43 char *arena; /* ignore */
44 GList *lineList; /* read-only */
45 GList *freeList; /* ignore */
46 GList *current; /* set implicitly or explicitly,
47 points to element of lineList */
48 shvarFile *parent; /* set explicitly */
49 int modified; /* ignore */
50};
51
52
de1fc6ce
JR
53/* Create the file <name>, return shvarFile on success, NULL on failure */
54shvarFile *
55svCreateFile(const char *name);
56
458f14b7
AM
57/* Open the file <name>, return shvarFile on success, NULL on failure */
58shvarFile *
de1fc6ce 59svNewFile(const char *name);
458f14b7
AM
60
61/* Get the value associated with the key, and leave the current pointer
62 * pointing at the line containing the value. The char* returned MUST
63 * be freed by the caller.
64 */
65char *
de1fc6ce 66svGetValue(shvarFile *s, const char *key);
458f14b7
AM
67
68/* return 1 if <key> resolves to any truth value (e.g. "yes", "y", "true")
69 * return 0 if <key> resolves to any non-truth value (e.g. "no", "n", "false")
70 * return <def> otherwise
71 */
72int
de1fc6ce 73svTrueValue(shvarFile *s, const char *key, int def);
458f14b7
AM
74
75/* Set the variable <key> equal to the value <value>.
76 * If <key> does not exist, and the <current> pointer is set, append
77 * the key=value pair after that line. Otherwise, prepend the pair
78 * to the top of the file.
79 */
80void
de1fc6ce 81svSetValue(shvarFile *s, const char *key, const char *value);
458f14b7
AM
82
83
163dcb78 84/* Write the current contents iff modified. Returns -1 on error
458f14b7
AM
85 * and 0 on success. Do not write if no values have been modified.
86 * The mode argument is only used if creating the file, not if
87 * re-writing an existing file, and is passed unchanged to the
88 * open() syscall.
89 */
90int
91svWriteFile(shvarFile *s, int mode);
92
93/* Close the file descriptor (if open) and delete the shvarFile.
94 * Returns -1 on error and 0 on success.
95 */
96int
97svCloseFile(shvarFile *s);
98
99#ifdef __cplusplus
100}
101#endif /* __cplusplus */
102
103#endif /* ! _SHVAR_H */
This page took 0.089359 seconds and 4 git commands to generate.