1SETENV(3)                  Linux Programmer's Manual                 SETENV(3)
2
3
4

NAME

6       setenv - change or add an environment variable
7

SYNOPSIS

9       #include <stdlib.h>
10
11       int setenv(const char *name, const char *value, int overwrite);
12
13       int unsetenv(const char *name);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       setenv(), unsetenv(): _BSD_SOURCE || _POSIX_C_SOURCE >= 200112L ||
18       _XOPEN_SOURCE >= 600
19

DESCRIPTION

21       The setenv() function adds the variable name to  the  environment  with
22       the value value, if name does not already exist.  If name does exist in
23       the environment, then its value is changed to  value  if  overwrite  is
24       nonzero;  if  overwrite is zero, then the value of name is not changed.
25       This function makes copies of the strings pointed to by name and  value
26       (by contrast with putenv(3)).
27
28       The unsetenv() function deletes the variable name from the environment.
29       If name does not exist in the environment, then the function  succeeds,
30       and the environment is unchanged.
31

RETURN VALUE

33       The  setenv()  function  returns  zero on success, or -1 on error, with
34       errno set to indicate the cause of the error.
35
36       The unsetenv() function returns zero on success, or -1 on  error,  with
37       errno set to indicate the cause of the error.
38

ERRORS

40       EINVAL name is NULL, points to a string of length 0, or contains an '='
41              character.
42
43       ENOMEM Insufficient memory to add a new variable to the environment.
44

CONFORMING TO

46       4.3BSD, POSIX.1-2001.
47

NOTES

49       POSIX.1-2001 does not require setenv() or unsetenv() to be reentrant.
50
51       Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more
52       recent glibc versions follow the POSIX.1-2001-compliant prototype shown
53       in the SYNOPSIS.
54

BUGS

56       POSIX.1-2001 specifies that if name contains  an  '='  character,  then
57       setenv()  should fail with the error EINVAL; however, versions of glibc
58       before 2.3.4 allowed an '=' sign in name.
59

SEE ALSO

61       clearenv(3), getenv(3), putenv(3), environ(7)
62

COLOPHON

64       This page is part of release 3.25 of the Linux  man-pages  project.   A
65       description  of  the project, and information about reporting bugs, can
66       be found at http://www.kernel.org/doc/man-pages/.
67
68
69
70GNU                               2009-09-20                         SETENV(3)
Impressum