From 871115c02a7adead20939c3f68371d92127861b8 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 21 Aug 2020 09:37:22 +0100 Subject: 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. --- win32/env.c | 13 ++++++------- 1 file 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) } /* - * Removing an environment variable with WIN32 putenv requires an argument + * Removing an environment variable with WIN32 _putenv requires an argument * like "NAME="; glibc omits the '='. The implementations of unsetenv and * clearenv allow for this. * * It isn't possible to create an environment variable with an empty value - * using WIN32 putenv. + * using WIN32 _putenv. */ int unsetenv(const char *name) { @@ -49,9 +49,8 @@ int unsetenv(const char *name) return -1; } - envstr = xmalloc(strlen(name)+2); - strcat(strcpy(envstr, name), "="); - ret = putenv(envstr); + envstr = xasprintf("%s=", name); + ret = _putenv(envstr); free(envstr); return ret; @@ -64,7 +63,7 @@ int clearenv(void) while ( environ && (envp=*environ) ) { if ( (s=strchr(envp, '=')) != NULL ) { name = xstrndup(envp, s-envp+1); - if ( putenv(name) == -1 ) { + if (_putenv(name) == -1) { free(name); return -1; } @@ -86,7 +85,7 @@ int mingw_putenv(const char *env) } if ( s[1] != '\0' ) { - return putenv(env); + return _putenv(env); } /* can't set empty value */ -- cgit v1.2.3-55-g6feb