aboutsummaryrefslogtreecommitdiffstats
path: root/common/sysutils.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-10-25 06:59:44 +0000
committerWerner Koch <[email protected]>2016-10-25 06:59:44 +0000
commit7983f8758703071710c11bf2a255efcd71836b65 (patch)
tree6c3829ca17d15f86c945cfb683be4eb78d4850af /common/sysutils.c
parentgpg: Replace two sprintf calls. (diff)
downloadgnupg-7983f8758703071710c11bf2a255efcd71836b65.tar.gz
gnupg-7983f8758703071710c11bf2a255efcd71836b65.zip
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 <[email protected]>
Diffstat (limited to 'common/sysutils.c')
-rw-r--r--common/sysutils.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index 85eb203fc..ab2012c45 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -754,8 +754,8 @@ gnupg_setenv (const char *name, const char *value, int overwrite)
(void)value;
(void)overwrite;
return 0;
-#else
-#if defined(HAVE_W32_SYSTEM)
+#else /*!W32CE*/
+# ifdef HAVE_W32_SYSTEM
/* Windows maintains (at least) two sets of environment variables.
One set can be accessed by GetEnvironmentVariable and
SetEnvironmentVariable. This set is inherited by the children.
@@ -773,11 +773,11 @@ gnupg_setenv (const char *name, const char *value, int overwrite)
return -1;
}
}
-#endif
+# endif /*W32*/
-#if defined(HAVE_SETENV)
+# ifdef HAVE_SETENV
return setenv (name, value, overwrite);
-#else
+# else /*!HAVE_SETENV*/
if (! getenv (name) || overwrite)
{
char *buf;
@@ -788,18 +788,17 @@ gnupg_setenv (const char *name, const char *value, int overwrite)
gpg_err_set_errno (EINVAL);
return -1;
}
- buf = xtrymalloc (strlen (name) + 1 + strlen (value) + 1);
+ buf = strconcat (name, "=", value, NULL);
if (!buf)
return -1;
- strcpy (stpcpy (stpcpy (buf, name), "="), value);
-#if __GNUC__
-# warning no setenv - using putenv but leaking memory.
-#endif
+# if __GNUC__
+# warning no setenv - using putenv but leaking memory.
+# endif
return putenv (buf);
}
return 0;
-#endif
-#endif
+# endif /*!HAVE_SETENV*/
+#endif /*!W32CE*/
}
@@ -809,8 +808,8 @@ gnupg_unsetenv (const char *name)
#ifdef HAVE_W32CE_SYSTEM
(void)name;
return 0;
-#else
-#if defined(HAVE_W32_SYSTEM)
+#else /*!W32CE*/
+# ifdef HAVE_W32_SYSTEM
/* Windows maintains (at least) two sets of environment variables.
One set can be accessed by GetEnvironmentVariable and
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.) */
return -1;
}
-#endif
-#if defined(HAVE_UNSETENV)
+# endif /*W32*/
+
+# ifdef HAVE_UNSETENV
return unsetenv (name);
-#else
+# else /*!HAVE_UNSETENV*/
{
char *buf;
@@ -837,13 +837,13 @@ gnupg_unsetenv (const char *name)
buf = xtrystrdup (name);
if (!buf)
return -1;
-#if __GNUC__
-# warning no unsetenv - trying putenv but leaking memory.
-#endif
+# if __GNUC__
+# warning no unsetenv - trying putenv but leaking memory.
+# endif
return putenv (buf);
}
-#endif
-#endif
+# endif /*!HAVE_UNSETENV*/
+#endif /*!W32CE*/
}