added doputenv(), dosetenv()
CVS patchset: 1251 CVS date: 1996/12/24 14:01:56
This commit is contained in:
parent
e03fdd3874
commit
02650a7185
30
lib/misc.c
30
lib/misc.c
|
@ -139,3 +139,33 @@ void stripTrailingSlashes(char * str) {
|
|||
chptr--;
|
||||
}
|
||||
}
|
||||
|
||||
int doputenv(const char *str) {
|
||||
char * a;
|
||||
|
||||
/* FIXME: this leaks memory! */
|
||||
|
||||
a = malloc(strlen(str) + 1);
|
||||
strcpy(a, str);
|
||||
|
||||
return putenv(a);
|
||||
}
|
||||
|
||||
int dosetenv(const char *name, const char *value, int overwrite) {
|
||||
int i;
|
||||
char * a;
|
||||
|
||||
/* FIXME: this leaks memory! */
|
||||
|
||||
if (!overwrite && getenv(name)) return 0;
|
||||
|
||||
i = strlen(name) + strlen(value) + 2;
|
||||
a = malloc(i);
|
||||
if (!a) return 1;
|
||||
|
||||
strcpy(a, name);
|
||||
strcat(a, "=");
|
||||
strcat(a, value);
|
||||
|
||||
return putenv(a);
|
||||
}
|
||||
|
|
|
@ -9,4 +9,9 @@ int exists(char * filespec);
|
|||
|
||||
int vercmp(char * one, char * two);
|
||||
|
||||
/* these are like the normal functions, but they malloc() the space which
|
||||
is needed */
|
||||
int dosetenv(const char *name, const char *value, int overwrite);
|
||||
int doputenv(const char * str);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue