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