nut/common/setenv.c

28 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;
2022-06-29 10:37:36 +00:00
2011-01-26 09:35:08 +00:00
if (overwrite == 0) {
val = getenv(name);
if (val != NULL) {
return 0;
}
}
2022-06-29 10:37:36 +00:00
2011-01-26 09:35:08 +00:00
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