source: trunk/sys/dietlibc/setenv.c @ 1

Last change on this file since 1 was 1, checked in by alain, 5 years ago

First import

File size: 520 bytes
Line 
1#include <string.h>
2#include <stdlib.h>
3#include <errno.h>
4
5#include "dietwarning.h"
6link_warning("setenv","setenv calls malloc.  Avoid it in small programs.");
7
8int setenv(const char *name, const char *value, int overwrite) {
9  if (getenv(name)) {
10    if (!overwrite) return 0;
11    unsetenv(name);
12  }
13  {
14    char *c=malloc(strlen(name) + strlen(value) + 2);
15
16    if(c == NULL)
17    {
18      errno = ENOMEM;
19      return -1;
20    }
21
22    strcpy(c,name);
23    strcat(c,"=");
24    strcat(c,value);
25    return putenv(c);
26  }
27}
Note: See TracBrowser for help on using the repository browser.