blob: 4066489ee0c2281db867dc462ce59971ded844bb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* See LICENSE file for copyright and license details. */
#include "internal.h"
void
liberror_setenv_failed(const char *envname, const char *envval, int overwrite)
{
const char *desc = "";
if (!envname) {
if (!envval)
desc = "Environment variable name and value are NULL";
else
desc = "Environment variable name is NULL";
} else if (!envval) {
desc = "Environment variable value is NULL";
} else if (!*envname) {
desc = "Environment variable name is the empty string";
} else if (errno == EINVAL) {
desc = "Environment variable name contains the '=' character";
}
liberror_set_error_errno(desc, "setenv", errno);
(void) overwrite;
}
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_save_backtrace(NULL);
liberror_set_error_errno(desc, "setenv", errno);
return -1;
}
|