added doputenv(), dosetenv()
authorewt <devnull@localhost>
Tue, 24 Dec 1996 14:01:56 +0000 (14:01 +0000)
committerewt <devnull@localhost>
Tue, 24 Dec 1996 14:01:56 +0000 (14:01 +0000)
CVS patchset: 1251
CVS date: 1996/12/24 14:01:56

lib/misc.c
lib/misc.h

index 59e91ee..4c87866 100644 (file)
@@ -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);
+}
index d2db68e..8d6fd0f 100644 (file)
@@ -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