diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-03-25 12:41:41 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-03-25 12:44:25 -0700 |
commit | 5b3a6f94f866b02761105b55dfdfad4379a640bf (patch) | |
tree | f11d0029599edc4c1196a1a4dce635cbf40c5f10 /lib/putenv.c | |
parent | a37df18aae6c52fab2c7efebff28585e5365268e (diff) | |
download | gnulib-5b3a6f94f866b02761105b55dfdfad4379a640bf.tar.gz |
free-posix: use more often in other modules
This lets us simplify cleanup code that calls ‘free’.
* lib/amemxfrm.c (amemxfrm):
* lib/areadlink-with-size.c (areadlink_with_size):
* lib/areadlinkat-with-size.c (areadlinkat_with_size):
* lib/astrxfrm.c (astrxfrm):
* lib/dprintf.c (dprintf):
* lib/execute.c (execute):
* lib/execvpe.c (execvpe):
* lib/fchdir.c (get_name):
* lib/file-has-acl.c (file_has_acl):
* lib/fprintf.c (fprintf):
* lib/getcwd-lgpl.c (rpl_getcwd):
* lib/getgroups.c (rpl_getgroups):
* lib/link.c (link, rpl_link):
* lib/linkat.c (link_immediate, link_follow, linkat_follow):
* lib/localename.c (newlocale, duplocale):
* lib/mgetgroups.c (mgetgroups):
* lib/mountlist.c (read_file_system_list):
* lib/pipe-filter-gi.c (pipe_filter_gi_close):
* lib/putenv.c (_unsetenv, putenv):
* lib/read-file.c (read_file):
* lib/rename.c (rpl_rename):
* lib/savedir.c (streamsavedir, savedir):
* lib/spawni.c (do_open, __spawni):
* lib/spawn-pipe.c (create_pipe):
* lib/striconv.c (mem_cd_iconv, str_cd_iconv, str_iconv):
* lib/striconveh.c (mem_cd_iconveh_internal, str_cd_iconveh)
(mem_iconveh, str_iconveh):
* lib/supersede.c (open_supersede, close_supersede):
* lib/vasnprintf.c (VASNPRINTF):
* lib/vdprintf.c (vdprintf):
* lib/vfprintf.c (vfprintf):
* lib/wcscoll-impl.h (wcscoll):
* lib/wcsxfrm-impl.h (wcsxfrm):
* lib/xgetdomainname.c (xgetdomainname):
* lib/xgethostname.c (xgethostname):
Simplify by assuming that ‘free’ preserves errno.
* lib/localename.c: Do not include errno.h.
* modules/amemxfrm, modules/areadlink-with-size:
* modules/areadlinkat-with-size, modules/astrxfrm:
* modules/c-vasnprintf, modules/dprintf, modules/execute:
* modules/execvpe, modules/fchdir, modules/file-has-acl:
* modules/fprintf-posix, modules/getcwd-lgpl, modules/getgroups:
* modules/link, modules/linkat, modules/localename:
* modules/mgetgroups, modules/mountlist, modules/pipe-filter-gi:
* modules/posix_spawn-internal, modules/putenv, modules/read-file:
* modules/rename, modules/savedir, modules/spawn-pipe:
* modules/striconv, modules/striconveh, modules/supersede:
* modules/vasnprintf, modules/vdprintf, modules/vfprintf-posix:
* modules/wcscoll, modules/wcsxfrm, modules/xgetdomainname:
* modules/xgethostname:
Depend on free-posix.
Diffstat (limited to 'lib/putenv.c')
-rw-r--r-- | lib/putenv.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/lib/putenv.c b/lib/putenv.c index a3f86c0e69..555474f4da 100644 --- a/lib/putenv.c +++ b/lib/putenv.c @@ -82,15 +82,13 @@ _unsetenv (const char *name) #if HAVE_DECL__PUTENV { - int putenv_result, putenv_errno; + int putenv_result; char *name_ = malloc (len + 2); memcpy (name_, name, len); name_[len] = '='; name_[len + 1] = 0; putenv_result = _putenv (name_); - putenv_errno = errno; free (name_); - __set_errno (putenv_errno); return putenv_result; } #else @@ -144,7 +142,7 @@ putenv (char *string) /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ") to allocate the environ vector and then replace the new entry with "NAME=". */ - int putenv_result, putenv_errno; + int putenv_result; char *name_x = malloc (name_end - string + sizeof "= "); if (!name_x) return -1; @@ -152,7 +150,6 @@ putenv (char *string) name_x[name_end - string + 1] = ' '; name_x[name_end - string + 2] = 0; putenv_result = _putenv (name_x); - putenv_errno = errno; for (ep = environ; *ep; ep++) if (strcmp (*ep, name_x) == 0) { @@ -166,11 +163,10 @@ putenv (char *string) fix that by calling SetEnvironmentVariable directly. */ name_x[name_end - string] = 0; putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1; - putenv_errno = ENOMEM; /* ENOMEM is the only way to fail. */ + errno = ENOMEM; /* ENOMEM is the only way to fail. */ } # endif free (name_x); - __set_errno (putenv_errno); return putenv_result; } #else |