1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-09-21 15:01:41 +02:00

common: Use strconcat in gnupg_setenv.

* common/sysutils.c (gnupg_setenv): Replace malloc+stpcpy by
strconcat.  Indent cpp conditionals.
(gnupg_unsetenv): Indent cpp conditionals.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-10-25 08:59:44 +02:00
parent 9d6146d6f9
commit 7983f87587
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -754,8 +754,8 @@ gnupg_setenv (const char *name, const char *value, int overwrite)
(void)value; (void)value;
(void)overwrite; (void)overwrite;
return 0; return 0;
#else #else /*!W32CE*/
#if defined(HAVE_W32_SYSTEM) # ifdef HAVE_W32_SYSTEM
/* Windows maintains (at least) two sets of environment variables. /* Windows maintains (at least) two sets of environment variables.
One set can be accessed by GetEnvironmentVariable and One set can be accessed by GetEnvironmentVariable and
SetEnvironmentVariable. This set is inherited by the children. SetEnvironmentVariable. This set is inherited by the children.
@ -773,11 +773,11 @@ gnupg_setenv (const char *name, const char *value, int overwrite)
return -1; return -1;
} }
} }
#endif # endif /*W32*/
#if defined(HAVE_SETENV) # ifdef HAVE_SETENV
return setenv (name, value, overwrite); return setenv (name, value, overwrite);
#else # else /*!HAVE_SETENV*/
if (! getenv (name) || overwrite) if (! getenv (name) || overwrite)
{ {
char *buf; char *buf;
@ -788,18 +788,17 @@ gnupg_setenv (const char *name, const char *value, int overwrite)
gpg_err_set_errno (EINVAL); gpg_err_set_errno (EINVAL);
return -1; return -1;
} }
buf = xtrymalloc (strlen (name) + 1 + strlen (value) + 1); buf = strconcat (name, "=", value, NULL);
if (!buf) if (!buf)
return -1; return -1;
strcpy (stpcpy (stpcpy (buf, name), "="), value); # if __GNUC__
#if __GNUC__
# warning no setenv - using putenv but leaking memory. # warning no setenv - using putenv but leaking memory.
#endif # endif
return putenv (buf); return putenv (buf);
} }
return 0; return 0;
#endif # endif /*!HAVE_SETENV*/
#endif #endif /*!W32CE*/
} }
@ -809,8 +808,8 @@ gnupg_unsetenv (const char *name)
#ifdef HAVE_W32CE_SYSTEM #ifdef HAVE_W32CE_SYSTEM
(void)name; (void)name;
return 0; return 0;
#else #else /*!W32CE*/
#if defined(HAVE_W32_SYSTEM) # ifdef HAVE_W32_SYSTEM
/* Windows maintains (at least) two sets of environment variables. /* Windows maintains (at least) two sets of environment variables.
One set can be accessed by GetEnvironmentVariable and One set can be accessed by GetEnvironmentVariable and
SetEnvironmentVariable. This set is inherited by the children. SetEnvironmentVariable. This set is inherited by the children.
@ -822,10 +821,11 @@ gnupg_unsetenv (const char *name)
gpg_err_set_errno (EINVAL); /* (Might also be ENOMEM.) */ gpg_err_set_errno (EINVAL); /* (Might also be ENOMEM.) */
return -1; return -1;
} }
#endif # endif /*W32*/
#if defined(HAVE_UNSETENV)
# ifdef HAVE_UNSETENV
return unsetenv (name); return unsetenv (name);
#else # else /*!HAVE_UNSETENV*/
{ {
char *buf; char *buf;
@ -837,13 +837,13 @@ gnupg_unsetenv (const char *name)
buf = xtrystrdup (name); buf = xtrystrdup (name);
if (!buf) if (!buf)
return -1; return -1;
#if __GNUC__ # if __GNUC__
# warning no unsetenv - trying putenv but leaking memory. # warning no unsetenv - trying putenv but leaking memory.
#endif # endif
return putenv (buf); return putenv (buf);
} }
#endif # endif /*!HAVE_UNSETENV*/
#endif #endif /*!W32CE*/
} }