diff options
author | Ron Yorston <rmy@pobox.com> | 2020-08-21 09:37:22 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-08-21 09:59:06 +0100 |
commit | 871115c02a7adead20939c3f68371d92127861b8 (patch) | |
tree | a028b0a8c59a20c960356aa25b6f9085082b0d15 | |
parent | d13ee992a2ee4be395f926913e33b18bf8ef1383 (diff) | |
download | busybox-w32-871115c02a7adead20939c3f68371d92127861b8.tar.gz busybox-w32-871115c02a7adead20939c3f68371d92127861b8.tar.bz2 busybox-w32-871115c02a7adead20939c3f68371d92127861b8.zip |
win32: env.c code shrink and clarification
Use xasprintf() to create string in unsetenv().
Clarify when we're using WIN32 _putenv().
No change in functionality; saves 16 bytes.
-rw-r--r-- | win32/env.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/win32/env.c b/win32/env.c index 2837c0720..a7ab7851a 100644 --- a/win32/env.c +++ b/win32/env.c | |||
@@ -33,12 +33,12 @@ int setenv(const char *name, const char *value, int replace) | |||
33 | } | 33 | } |
34 | 34 | ||
35 | /* | 35 | /* |
36 | * Removing an environment variable with WIN32 putenv requires an argument | 36 | * Removing an environment variable with WIN32 _putenv requires an argument |
37 | * like "NAME="; glibc omits the '='. The implementations of unsetenv and | 37 | * like "NAME="; glibc omits the '='. The implementations of unsetenv and |
38 | * clearenv allow for this. | 38 | * clearenv allow for this. |
39 | * | 39 | * |
40 | * It isn't possible to create an environment variable with an empty value | 40 | * It isn't possible to create an environment variable with an empty value |
41 | * using WIN32 putenv. | 41 | * using WIN32 _putenv. |
42 | */ | 42 | */ |
43 | int unsetenv(const char *name) | 43 | int unsetenv(const char *name) |
44 | { | 44 | { |
@@ -49,9 +49,8 @@ int unsetenv(const char *name) | |||
49 | return -1; | 49 | return -1; |
50 | } | 50 | } |
51 | 51 | ||
52 | envstr = xmalloc(strlen(name)+2); | 52 | envstr = xasprintf("%s=", name); |
53 | strcat(strcpy(envstr, name), "="); | 53 | ret = _putenv(envstr); |
54 | ret = putenv(envstr); | ||
55 | free(envstr); | 54 | free(envstr); |
56 | 55 | ||
57 | return ret; | 56 | return ret; |
@@ -64,7 +63,7 @@ int clearenv(void) | |||
64 | while ( environ && (envp=*environ) ) { | 63 | while ( environ && (envp=*environ) ) { |
65 | if ( (s=strchr(envp, '=')) != NULL ) { | 64 | if ( (s=strchr(envp, '=')) != NULL ) { |
66 | name = xstrndup(envp, s-envp+1); | 65 | name = xstrndup(envp, s-envp+1); |
67 | if ( putenv(name) == -1 ) { | 66 | if (_putenv(name) == -1) { |
68 | free(name); | 67 | free(name); |
69 | return -1; | 68 | return -1; |
70 | } | 69 | } |
@@ -86,7 +85,7 @@ int mingw_putenv(const char *env) | |||
86 | } | 85 | } |
87 | 86 | ||
88 | if ( s[1] != '\0' ) { | 87 | if ( s[1] != '\0' ) { |
89 | return putenv(env); | 88 | return _putenv(env); |
90 | } | 89 | } |
91 | 90 | ||
92 | /* can't set empty value */ | 91 | /* can't set empty value */ |