]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/setenv.3
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[thirdparty/man-pages.git] / man3 / setenv.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2004, 2007 Michael kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(verbatim)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" References consulted:
27 .\" Linux libc source code
28 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
29 .\" 386BSD man pages
30 .\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
32 .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Changed unsetenv() prototype; added EINVAL error
34 .\" Noted nonstandard behavior of setenv() if name contains '='
35 .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug
36 .\"
37 .TH SETENV 3 2009-09-20 "GNU" "Linux Programmer's Manual"
38 .SH NAME
39 setenv \- change or add an environment variable
40 .SH SYNOPSIS
41 .nf
42 .B #include <stdlib.h>
43 .sp
44 .BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
45 .sp
46 .BI "int unsetenv(const char *" name );
47 .fi
48 .sp
49 .in -4n
50 Feature Test Macro Requirements for glibc (see
51 .BR feature_test_macros (7)):
52 .in
53 .sp
54 .ad l
55 .BR setenv (),
56 .BR unsetenv ():
57 .RS 4
58 _BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
59 .RE
60 .ad b
61 .SH DESCRIPTION
62 The
63 .BR setenv ()
64 function adds the variable \fIname\fP to the
65 environment with the value \fIvalue\fP, if \fIname\fP does not
66 already exist.
67 If \fIname\fP does exist in the environment, then
68 its value is changed to \fIvalue\fP if \fIoverwrite\fP is nonzero;
69 if \fIoverwrite\fP is zero, then the value of \fIname\fP is not
70 changed.
71 This function makes copies of the strings pointed to by
72 .I name
73 and
74 .I value
75 (by contrast with
76 .BR putenv (3)).
77 .PP
78 The
79 .BR unsetenv ()
80 function deletes the variable \fIname\fP from
81 the environment.
82 If
83 .I name
84 does not exist in the environment,
85 then the function succeeds, and the environment is unchanged.
86 .SH RETURN VALUE
87 The
88 .BR setenv ()
89 function returns zero on success,
90 or \-1 on error, with
91 .I errno
92 set to indicate the cause of the error.
93
94 The
95 .BR unsetenv ()
96 function returns zero on success,
97 or \-1 on error, with
98 .I errno
99 set to indicate the cause of the error.
100 .SH ERRORS
101 .TP
102 .B EINVAL
103 .I name
104 is NULL, points to a string of length 0,
105 or contains an \(aq=\(aq character.
106 .TP
107 .B ENOMEM
108 Insufficient memory to add a new variable to the environment.
109 .SH CONFORMING TO
110 4.3BSD, POSIX.1-2001.
111 .SH NOTES
112 POSIX.1-2001 does not require
113 .BR setenv ()
114 or
115 .BR unsetenv ()
116 to be reentrant.
117
118 Prior to glibc 2.2.2,
119 .BR unsetenv ()
120 was prototyped
121 as returning \fIvoid\fP; more recent glibc versions follow the
122 POSIX.1-2001-compliant prototype shown in the SYNOPSIS.
123 .SH BUGS
124 POSIX.1-2001 specifies that if
125 .I name
126 contains an \(aq=\(aq character, then
127 .BR setenv ()
128 should fail with the error
129 .BR EINVAL ;
130 however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in
131 .IR name .
132 .SH SEE ALSO
133 .BR clearenv (3),
134 .BR getenv (3),
135 .BR putenv (3),
136 .BR environ (7)