Rev | Line | |
---|
[1] | 1 | #include <string.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <errno.h> |
---|
| 4 | |
---|
| 5 | #include "dietwarning.h" |
---|
| 6 | link_warning("setenv","setenv calls malloc. Avoid it in small programs."); |
---|
| 7 | |
---|
| 8 | int 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.