diff options
author | Mattias Andrée <maandree@kth.se> | 2019-04-12 21:12:31 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-04-12 21:13:37 +0200 |
commit | bafb07a1644896d56ad4b8effaeaae601c5a275b (patch) | |
tree | ef4e38f529ba2f0cadc73ad88493a1cca206fe7b /setenv.c | |
download | liberror-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 'setenv.c')
-rw-r--r-- | setenv.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/setenv.c b/setenv.c new file mode 100644 index 0000000..157fea2 --- /dev/null +++ b/setenv.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "internal.h" + + +int +liberror_setenv(const char *envname, const char *envval, int overwrite) +{ + const char *desc = ""; + if (!envname) { + errno = EINVAL; + if (!envval) + desc = "Environment variable name and value are NULL"; + else + desc = "Environment variable name is NULL"; + goto error; + } else if (!envval) { + errno = EINVAL; + desc = "Environment variable value is NULL"; + goto error; + } else if (!setenv(envname, envval, overwrite)) { + return 0; + } else if (!*envname) { + desc = "Environment variable name is the empty string"; + } else if (errno == EINVAL) { + desc = "Environment variable name contains the '=' character"; + } +error: + liberror_set_error_errno(desc, "setenv", errno); + return -1; +} |