OSDN Git Service

fe63a88eac356a77ab9f6499202dd225871007e5
[linuxjm/LDP_man-pages.git] / original / 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  2013-10-11 "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
65 .I name
66 to the
67 environment with the value
68 .IR value ,
69 if
70 .I name
71 does not
72 already exist.
73 If
74 .I name
75 does exist in the environment, then
76 its value is changed to
77 .IR value
78 if
79 .I overwrite
80 is nonzero;
81 if
82 .IR overwrite
83 is zero, then the value of
84 .I name
85 is not changed (and
86 .BR setenv ()
87 returns a success status).
88 This function makes copies of the strings pointed to by
89 .I name
90 and
91 .I value
92 (by contrast with
93 .BR putenv (3)).
94 .PP
95 The
96 .BR unsetenv ()
97 function deletes the variable
98 .I name
99 from
100 the environment.
101 If
102 .I name
103 does not exist in the environment,
104 then the function succeeds, and the environment is unchanged.
105 .SH RETURN VALUE
106 The
107 .BR setenv ()
108 function returns zero on success,
109 or \-1 on error, with
110 .I errno
111 set to indicate the cause of the error.
112
113 The
114 .BR unsetenv ()
115 function returns zero on success,
116 or \-1 on error, with
117 .I errno
118 set to indicate the cause of the error.
119 .SH ERRORS
120 .TP
121 .B EINVAL
122 .I name
123 is NULL, points to a string of length 0,
124 or contains an \(aq=\(aq character.
125 .TP
126 .B ENOMEM
127 Insufficient memory to add a new variable to the environment.
128 .SH CONFORMING TO
129 4.3BSD, POSIX.1-2001.
130 .SH NOTES
131 POSIX.1-2001 does not require
132 .BR setenv ()
133 or
134 .BR unsetenv ()
135 to be reentrant.
136
137 Prior to glibc 2.2.2,
138 .BR unsetenv ()
139 was prototyped
140 as returning
141 .IR void ;
142 more recent glibc versions follow the
143 POSIX.1-2001-compliant prototype shown in the SYNOPSIS.
144 .SH BUGS
145 POSIX.1-2001 specifies that if
146 .I name
147 contains an \(aq=\(aq character, then
148 .BR setenv ()
149 should fail with the error
150 .BR EINVAL ;
151 however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in
152 .IR name .
153 .SH SEE ALSO
154 .BR clearenv (3),
155 .BR getenv (3),
156 .BR putenv (3),
157 .BR environ (7)
158 .SH COLOPHON
159 This page is part of release 3.79 of the Linux
160 .I man-pages
161 project.
162 A description of the project,
163 information about reporting bugs,
164 and the latest version of this page,
165 can be found at
166 \%http://www.kernel.org/doc/man\-pages/.