diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2024-10-20 15:21:58 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2024-10-20 15:21:58 +0200 |
commit | 630f99f29bd31a76d8d24da2975a045452c763ef (patch) | |
tree | 0c801f68561bfb0930a4ade80d7ca3a7940887ab /tests/unsetenv.c | |
parent | 84e26c587987e8484d55db4165f188b40c09e94b (diff) | |
parent | 4682deeb62247d34de87f8e777f99e2d337fd377 (diff) |
Update upstream source from tag 'upstream/1.3'
Update to upstream version '1.3'
with Debian dir 8a8e4828ddf646ece6c109b401e08d162be35936
Diffstat (limited to 'tests/unsetenv.c')
-rw-r--r-- | tests/unsetenv.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/unsetenv.c b/tests/unsetenv.c index d8ada2aa..5e989968 100644 --- a/tests/unsetenv.c +++ b/tests/unsetenv.c @@ -57,7 +57,6 @@ int unsetenv (const char *name) { size_t len; - char **ep; if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { @@ -67,9 +66,37 @@ unsetenv (const char *name) len = strlen (name); +#if HAVE_DECL__PUTENV /* native Windows */ + /* The Microsoft documentation + <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/putenv-wputenv> + says: + "Don't change an environment entry directly: instead, + use _putenv or _wputenv to change it." + Note: Microsoft's _putenv updates not only the contents of _environ but + also the contents of _wenviron, so that both are in kept in sync. + + The way to remove an environment variable is to pass to _putenv a string + of the form "NAME=". (NB: This is a different convention than with glibc + putenv, which expects a string of the form "NAME"!) */ + { + int putenv_result; + char *name_ = malloc (len + 2); + if (name_ == NULL) + return -1; + memcpy (name_, name, len); + name_[len] = '='; + name_[len + 1] = 0; + putenv_result = _putenv (name_); + /* In this particular case it is OK to free() the argument passed to + _putenv. */ + free (name_); + return putenv_result; + } +#else + LOCK; - ep = __environ; + char **ep = __environ; while (*ep != NULL) if (!strncmp (*ep, name, len) && (*ep)[len] == '=') { @@ -87,6 +114,7 @@ unsetenv (const char *name) UNLOCK; return 0; +#endif } #ifdef _LIBC |