toaruos/libc/stdlib/setenv.c
2018-05-02 19:25:03 +09:00

17 lines
334 B
C

#include <stdlib.h>
#include <string.h>
int setenv(const char *name, const char *value, int overwrite) {
if (!overwrite) {
char * tmp = getenv(name);
if (tmp)
return 0;
}
char * tmp = malloc(strlen(name) + strlen(value) + 2);
*tmp = '\0';
strcat(tmp, name);
strcat(tmp, "=");
strcat(tmp, value);
return putenv(tmp);
}