#if !defined(lint) && !defined(LINT)
static char rcsid
[] = "$Header: env.c,v 2.2 90/07/18 00:23:48 vixie Exp $";
/* Copyright 1988,1990 by Paul Vixie
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
* paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
register char **p
= (char **) malloc(sizeof(char **));
extern char *realloc(), *savestr();
register int count
, found
;
* count the number of elements, including the null pointer;
* also set 'found' to -1 or index of entry if already in here.
for (count
= 0; envp
[count
] != NULL
; count
++)
if (!strcmp_until(envp
[count
], envstr
, '='))
count
++; /* for the null pointer
* it exists already, so just free the existing setting,
* save our new one there, and return the existing array.
envp
[found
] = savestr(envstr
);
* it doesn't exist yet, so resize the array, move null pointer over
* one, save our string over the old null pointer, and return resized
(unsigned) ((count
+1) * sizeof(char **))
p
[count
-1] = savestr(envstr
);
/* return ERR = end of file
* FALSE = not an env setting (file was repositioned)
* TRUE = was an env setting
char *strcpy(), *sprintf();
char name
[MAX_TEMPSTR
], val
[MAX_ENVSTR
];
if (EOF
== get_string(envstr
, MAX_ENVSTR
, f
, "\n"))
Debug(DPARS
, ("load_env, read <%s>\n", envstr
))
fields
= sscanf(envstr
, "%[^ =] = %[^\n#]", name
, val
);
Debug(DPARS
, ("load_env, not 2 fields (%d)\n", fields
))
/* 2 fields from scanf; looks like an env setting
if (val
[0] == '\'' || val
[0] == '"')
if (val
[len
-1] == val
[0])
(void) strcpy(val
, val
+1);
(void) sprintf(envstr
, "%s=%s", name
, val
);
Debug(DPARS
, ("load_env, <%s> <%s> -> <%s>\n", name
, val
, envstr
))
if (!strcmp_until(*envp
, name
, '='))
return index(*envp
, '=') + 1;