1 /* Copyright 1988,1990,1993 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 char rcsid
[] = "$Id: env.c,v 1.1 1994/01/05 20:40:14 jtc Exp $";
30 register char **p
= (char **) malloc(sizeof(char **));
42 register int count
, found
;
46 * count the number of elements, including the null pointer;
47 * also set 'found' to -1 or index of entry if already in here.
50 for (count
= 0; envp
[count
] != NULL
; count
++) {
51 if (!strcmp_until(envp
[count
], envstr
, '='))
54 count
++; /* for the null pointer
59 * it exists already, so just free the existing setting,
60 * save our new one there, and return the existing array.
63 envp
[found
] = strdup(envstr
);
68 * it doesn't exist yet, so resize the array, move null pointer over
69 * one, save our string over the old null pointer, and return resized
72 p
= (char **) realloc((void *) envp
,
73 (unsigned) ((count
+1) * sizeof(char **)));
74 p
[count
] = p
[count
-1];
75 p
[count
-1] = strdup(envstr
);
80 /* return ERR = end of file
81 * FALSE = not an env setting (file was repositioned)
82 * TRUE = was an env setting
91 char name
[MAX_TEMPSTR
], val
[MAX_ENVSTR
];
95 fileline
= LineNumber
;
97 if (EOF
== get_string(envstr
, MAX_ENVSTR
, f
, "\n"))
100 Debug(DPARS
, ("load_env, read <%s>\n", envstr
))
102 name
[0] = val
[0] = '\0';
103 fields
= sscanf(envstr
, "%[^ =] = %[^\n#]", name
, val
);
105 Debug(DPARS
, ("load_env, not 2 fields (%d)\n", fields
))
106 fseek(f
, filepos
, 0);
107 Set_LineNum(fileline
);
111 /* 2 fields from scanf; looks like an env setting
115 * process value string
118 int len
= strdtb(val
);
121 if (val
[0] == '\'' || val
[0] == '"') {
122 if (val
[len
-1] == val
[0]) {
124 (void) strcpy(val
, val
+1);
130 (void) sprintf(envstr
, "%s=%s", name
, val
);
131 Debug(DPARS
, ("load_env, <%s> <%s> -> <%s>\n", name
, val
, envstr
))
141 for (; *envp
; envp
++)
142 if (!strcmp_until(*envp
, name
, '='))
143 return strchr(*envp
, '=') + 1;