aboutsummaryrefslogtreecommitdiffstats
path: root/putenv.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-04-12 21:12:31 +0200
committerMattias Andrée <maandree@kth.se>2019-04-12 21:13:37 +0200
commitbafb07a1644896d56ad4b8effaeaae601c5a275b (patch)
treeef4e38f529ba2f0cadc73ad88493a1cca206fe7b /putenv.c
downloadliberror-libc-bafb07a1644896d56ad4b8effaeaae601c5a275b.tar.gz
liberror-libc-bafb07a1644896d56ad4b8effaeaae601c5a275b.tar.bz2
liberror-libc-bafb07a1644896d56ad4b8effaeaae601c5a275b.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'putenv.c')
-rw-r--r--putenv.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/putenv.c b/putenv.c
new file mode 100644
index 0000000..b88b3cd
--- /dev/null
+++ b/putenv.c
@@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include "internal.h"
+
+
+int
+liberror_putenv(char *string)
+{
+ const char *desc = "";
+ if (!string) {
+ errno = EINVAL;
+ desc = "Environment string is NULL";
+ goto error;
+ } else if (*string == '=') {
+ errno = EINVAL;
+ desc = "Environment variable name is the empty string";
+ goto error;
+ } else if (!strchr(string, '=')) {
+ errno = EINVAL;
+ desc = "Environment does not contain an '=' symbol";
+ goto error;
+ } else if (!putenv(string)) {
+ return 0;
+ }
+error:
+ liberror_set_error_errno(desc, "putenv", errno);
+ return -1;
+}