1 /* Copyright 1988,1990,1993,1994 by Paul Vixie
4 * Distribute freely, except: don't remove my name from the source or
5 * documentation (don't take credit for my work), mark your changes (don't
6 * get me blamed for your possible bugs), don't alter or remove this
7 * notice. May be sold if buildable source is provided to buyer. No
8 * warrantee of any kind, express or implied, is included with this
9 * software; use at your own risk, responsibility for damages (if any) to
10 * anyone resulting from the use of this software rests entirely with the
13 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
14 * I'll try to keep a version up to date. I can be reached as follows:
15 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
18 #if !defined(lint) && !defined(LINT)
19 static const char rcsid[] =
30 register char **p = (char **) malloc(sizeof(char **));
44 for (p = envp; *p; p++)
54 register int count, i;
57 for (count = 0; envp[count] != NULL; count++)
59 p = (char **) malloc((count+1) * sizeof(char **)); /* 1 for the NULL */
64 for (i = 0; i < count; i++)
65 if ((p[i] = strdup(envp[i])) == NULL) {
82 register int count, found;
87 * count the number of elements, including the null pointer;
88 * also set 'found' to -1 or index of entry if already in here.
91 for (count = 0; envp[count] != NULL; count++) {
92 if (!strcmp_until(envp[count], envstr, '='))
95 count++; /* for the NULL */
99 * it exists already, so just free the existing setting,
100 * save our new one there, and return the existing array.
103 if ((envp[found] = strdup(envstr)) == NULL) {
105 /* XXX env_free(envp); */
114 * it doesn't exist yet, so resize the array, move null pointer over
115 * one, save our string over the old null pointer, and return resized
118 p = (char **) realloc((void *) envp,
119 (unsigned) ((count+1) * sizeof(char **)));
121 /* XXX env_free(envp); */
125 p[count] = p[count-1];
126 if ((p[count-1] = strdup(envstr)) == NULL) {
135 /* return ERR = end of file
136 * FALSE = not an env setting (file was repositioned)
137 * TRUE = was an env setting
146 char name[MAX_ENVSTR], val[MAX_ENVSTR];
150 fileline = LineNumber;
152 if (EOF == get_string(envstr, MAX_ENVSTR, f, "\n"))
155 Debug(DPARS, ("load_env, read <%s>\n", envstr))
157 name[0] = val[0] = '\0';
158 fields = sscanf(envstr, "%[^ =] = %[^\n#]", name, val);
160 Debug(DPARS, ("load_env, not 2 fields (%d)\n", fields))
161 fseek(f, filepos, 0);
162 Set_LineNum(fileline);
166 /* 2 fields from scanf; looks like an env setting
170 * process value string
173 int len = strdtb(val);
176 if (val[0] == '\'' || val[0] == '"') {
177 if (val[len-1] == val[0]) {
179 (void) strcpy(val, val+1);
185 if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1)
187 (void) sprintf(envstr, "%s=%s", name, val);
188 Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr))
196 register char **envp;
198 register int len = strlen(name);
199 register char *p, *q;
201 while ((p = *envp++)) {
202 if (!(q = strchr(p, '=')))
204 if ((q - p) == len && !strncmp(p, name, len))