nut-debian/common/setenv.c

28 lines
529 B
C
Raw Normal View History

2011-01-26 11:35:08 +02: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-07-10 10:23:45 +03:00
2011-01-26 11:35:08 +02:00
if (overwrite == 0) {
val = getenv(name);
if (val != NULL) {
return 0;
}
}
2022-07-10 10:23:45 +03:00
2011-01-26 11:35:08 +02: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