version 1.1, 1999/11/18 16:29:01 |
version 1.2, 2000/11/21 17:58:44 |
|
|
#endif /* !STDC_HEADERS */ |
#endif /* !STDC_HEADERS */ |
|
|
#ifndef lint |
#ifndef lint |
static const char rcsid[] = "$Sudo: sudo_setenv.c,v 1.40 1999/07/31 16:19:48 millert Exp $"; |
static const char rcsid[] = "$Sudo: sudo_setenv.c,v 1.41 2000/09/14 20:48:58 millert Exp $"; |
#endif /* lint */ |
#endif /* lint */ |
|
|
|
|
/* |
/* |
* Add a string of the form "var=val" to the environment. If we are unable |
* Add a string of the form "var=val" to the environment. Exits if it is |
* to expand the current environent, return -1, else return 0. |
* unable to expand the current environent. |
*/ |
*/ |
int |
void |
sudo_setenv(var, val) |
sudo_setenv(var, val) |
char *var; |
char *var; |
char *val; |
char *val; |
{ |
{ |
|
|
#ifdef HAVE_SETENV |
#ifdef HAVE_SETENV |
return(setenv(var, val, 1)); |
if (setenv(var, val, 1) == -1) { |
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); |
|
exit(1); |
|
} |
#else |
#else |
char *envstring, *tmp; |
char *envstring, *tmp; |
|
|
envstring = tmp = (char *) malloc(strlen(var) + strlen(val) + 2); |
envstring = tmp = (char *) malloc(strlen(var) + strlen(val) + 2); |
if (envstring == NULL) |
if (envstring == NULL) { |
return(-1); |
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); |
|
exit(1); |
|
} |
|
|
while ((*tmp++ = *var++)) |
while ((*tmp++ = *var++)) |
; |
; |
|
|
while ((*tmp++ = *val++)) |
while ((*tmp++ = *val++)) |
; |
; |
|
|
return(putenv(envstring)); |
putenv(envstring); |
#endif /* HAVE_SETENV */ |
#endif /* HAVE_SETENV */ |
} |
} |