nut/common/setenv.c

27 lines
529 B
C
Raw Normal View History

2011-01-26 09:35:08 +00:00
/* setenv.c Ben Collver <collver@softhome.net> */
#ifndef HAVE_SETENV
#include <stdlib.h>
#include <string.h>
#include "common.h"
int nut_setenv(const char *name, const char *value, int overwrite)
{
char *val;
char *buffer;
int rv;
if (overwrite == 0) {
val = getenv(name);
if (val != NULL) {
return 0;
}
}
buffer = xmalloc(strlen(value) + strlen(name) + 2);
strcpy(buffer, name);
strcat(buffer, "=");
strcat(buffer, value);
rv = putenv(buffer); /* man putenv, do not free(buffer) */
return (rv);
}
#endif