| 1 | /* This implementation of setenv has a space leak, but I don't see how to avoid |
| 2 | * it, since the specification of putenv is that it uses the memory for its arg. |
| 3 | */ |
| 4 | int setenv (const char *name, const char *value, int overwrite) { |
| 5 | size_t len; |
| 6 | char *b; |
| 7 | |
| 8 | if (!overwrite && getenv (name)) |
| 9 | return 0; |
| 10 | |
| 11 | len = strlen (name) + strlen (value) + 2 /* = and \000 */; |
| 12 | b = malloc (len); |
| 13 | snprintf (b, len, "%s=%s", name, value); |
| 14 | return putenv (b); |
| 15 | } |