From 02650a718564ca2c2a7fbd1cc16337b76341e51a Mon Sep 17 00:00:00 2001 From: ewt Date: Tue, 24 Dec 1996 14:01:56 +0000 Subject: [PATCH] added doputenv(), dosetenv() CVS patchset: 1251 CVS date: 1996/12/24 14:01:56 --- lib/misc.c | 30 ++++++++++++++++++++++++++++++ lib/misc.h | 5 +++++ 2 files changed, 35 insertions(+) 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 -- 2.7.4