summaryrefslogtreecommitdiffstats
path: root/gl/unsetenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/unsetenv.c')
-rw-r--r--gl/unsetenv.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/gl/unsetenv.c b/gl/unsetenv.c
index d38ed37a..dab1b90c 100644
--- a/gl/unsetenv.c
+++ b/gl/unsetenv.c
@@ -1,4 +1,4 @@
1/* Copyright (C) 1992, 1995-2002, 2005-2025 Free Software Foundation, Inc. 1/* Copyright (C) 1992, 1995-2002, 2005-2026 Free Software Foundation, Inc.
2 This file is part of the GNU C Library. 2 This file is part of the GNU C Library.
3 3
4 This file is free software: you can redistribute it and/or modify 4 This file is free software: you can redistribute it and/or modify
@@ -56,15 +56,13 @@ __libc_lock_define_initialized (static, envlock)
56int 56int
57unsetenv (const char *name) 57unsetenv (const char *name)
58{ 58{
59 size_t len;
60
61 if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) 59 if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
62 { 60 {
63 __set_errno (EINVAL); 61 __set_errno (EINVAL);
64 return -1; 62 return -1;
65 } 63 }
66 64
67 len = strlen (name); 65 size_t len = strlen (name);
68 66
69#if HAVE_DECL__PUTENV /* native Windows */ 67#if HAVE_DECL__PUTENV /* native Windows */
70 /* The Microsoft documentation 68 /* The Microsoft documentation
@@ -79,14 +77,13 @@ unsetenv (const char *name)
79 of the form "NAME=". (NB: This is a different convention than with glibc 77 of the form "NAME=". (NB: This is a different convention than with glibc
80 putenv, which expects a string of the form "NAME"!) */ 78 putenv, which expects a string of the form "NAME"!) */
81 { 79 {
82 int putenv_result;
83 char *name_ = malloc (len + 2); 80 char *name_ = malloc (len + 2);
84 if (name_ == NULL) 81 if (name_ == NULL)
85 return -1; 82 return -1;
86 memcpy (name_, name, len); 83 memcpy (name_, name, len);
87 name_[len] = '='; 84 name_[len] = '=';
88 name_[len + 1] = 0; 85 name_[len + 1] = 0;
89 putenv_result = _putenv (name_); 86 int putenv_result = _putenv (name_);
90 /* In this particular case it is OK to free() the argument passed to 87 /* In this particular case it is OK to free() the argument passed to
91 _putenv. */ 88 _putenv. */
92 free (name_); 89 free (name_);
@@ -138,12 +135,12 @@ extern int unsetenv (const char *);
138int 135int
139rpl_unsetenv (const char *name) 136rpl_unsetenv (const char *name)
140{ 137{
141 int result = 0;
142 if (!name || !*name || strchr (name, '=')) 138 if (!name || !*name || strchr (name, '='))
143 { 139 {
144 errno = EINVAL; 140 errno = EINVAL;
145 return -1; 141 return -1;
146 } 142 }
143 int result = 0;
147 while (getenv (name)) 144 while (getenv (name))
148# if !VOID_UNSETENV 145# if !VOID_UNSETENV
149 result = 146 result =