From: ewt Date: Tue, 24 Dec 1996 14:01:56 +0000 (+0000) Subject: added doputenv(), dosetenv() X-Git-Tag: rpm-4.4-release~4484 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02650a718564ca2c2a7fbd1cc16337b76341e51a;p=platform%2Fupstream%2Frpm.git added doputenv(), dosetenv() CVS patchset: 1251 CVS date: 1996/12/24 14:01:56 --- diff --git a/lib/misc.c b/lib/misc.c index 59e91ee..4c87866 100644 --- a/lib/misc.c +++ b/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); +} diff --git a/lib/misc.h b/lib/misc.h index d2db68e..8d6fd0f 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -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