my previous version was wrong; this one is right
[unix-history] / usr / src / lib / libc / stdlib / getenv.3
CommitLineData
31b20f0a
KB
1.\" Copyright (c) 1988 The Regents of the University of California.
2.\" All rights reserved.
c80211f9 3.\"
adb19fe0 4.\" %sccs.include.redist.man%
31b20f0a 5.\"
58e8ceb7 6.\" @(#)getenv.3 6.9 (Berkeley) %G%
31b20f0a 7.\"
500e7be1 8.TH GETENV 3 ""
c80211f9
KM
9.AT 3
10.SH NAME
79fc0f61 11getenv, putenv, setenv, unsetenv \- manipulate environmental variables
c80211f9
KM
12.SH SYNOPSIS
13.nf
adb19fe0 14.ft B
58e8ceb7
KB
15#include <stdlib.h>
16
adb19fe0
KB
17char *
18getenv(const char *name);
19
20setenv(const char *name, const char *value, int overwrite);
21
22putenv(const char *string);
23
24void
25unsetenv(const char *name);
26.ft R
c80211f9
KM
27.fi
28.SH DESCRIPTION
adb19fe0
KB
29.I Getenv
30searches the environment list (see
31.IR environ (7))
4f3c5ada 32for a string of the form \fIname\fP\fB=\fP\fIvalue\fP and returns
adb19fe0
KB
33a pointer to the string
34.I value
35if such a string is present, and a NULL pointer if it is not.
4f3c5ada 36.PP
adb19fe0
KB
37.I Setenv
38searches the environment list as
39.I getenv
40does; if the string
41.I name
42is not found, a string of the form \fIname\fP\fB=\fP\fIvalue\fP is
43added to the environment.
44If it is found, and
45.I overwrite
46is non-zero, its value is changed to
47.IR value .
48.I Setenv
49returns 0 on success and -1 on failure, setting the external variable
50.IR errno .
4f3c5ada 51.PP
79fc0f61 52.I Putenv
adb19fe0
KB
53takes an argument of the form ``\fIname\fR=\fIvalue\fR'' and is the
54equivalent of:
55.sp
56.RS
57setenv(name, value, 1);
58.RE
0125ac17 59.PP
adb19fe0
KB
60.I Unsetenv
61removes all occurrences of the string
62.I name
63from the environment.
64There is no library provision for completely removing the current
65environment.
66It is suggested that the following code be used to do so.
67.sp
68.RS
0125ac17 69.nf
adb19fe0
KB
70static char *envinit[1];
71extern char **environ;
72environ = envinit;
0125ac17 73.fi
adb19fe0 74.RE
4f3c5ada
KB
75.PP
76All of these routines permit, but do not require, a trailing equals
adb19fe0
KB
77(``='') sign on
78.I name
79or a leading equals sign on
80.IR value .
81.SH ERRORS
82.TP
83[ENOMEM]
84.I Setenv
85or
86.I putenv
87failed because they were unable to allocate memory for the environment.
c80211f9 88.SH SEE ALSO
4f3c5ada 89csh(1), sh(1), execve(2), environ(7)
adb19fe0
KB
90.SH STANDARDS
91.B Getenv
92conforms to ANSI X3.159-1989 (``ANSI C'').