source: projects/initscripts/tags/initscripts-8.91.3/src/shvar.h @ 1108

Revision 1108, 3.1 KB checked in by daisuke, 13 years ago (diff)

import initscripts-8.90.6 from internal cvs repository

Line 
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
53/* Create the file <name>, return shvarFile on success, NULL on failure */
54shvarFile *
55svCreateFile(const char *name);
56
57/* Open the file <name>, return shvarFile on success, NULL on failure */
58shvarFile *
59svNewFile(const char *name);
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 *
66svGetValue(shvarFile *s, const char *key);
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
73svTrueValue(shvarFile *s, const char *key, int def);
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
81svSetValue(shvarFile *s, const char *key, const char *value);
82
83
84/* Write the current contents iff modified.  Returns -1 on error
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 */
Note: See TracBrowser for help on using the repository browser.