date and time created 89/02/14 20:32:54 by bostic
[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.\"
31b20f0a
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
5da6f084 16.\" @(#)getenv.3 6.6 (Berkeley) %G%
31b20f0a 17.\"
500e7be1 18.TH GETENV 3 ""
c80211f9
KM
19.AT 3
20.SH NAME
4f3c5ada 21getenv, setenv, unsetenv \- manipulate environmental variables
c80211f9
KM
22.SH SYNOPSIS
23.nf
24.B char *getenv(name)
25.B char *name;
4f3c5ada
KB
26.PP
27.B setenv(name, value, overwrite)
28.B char *name, value;
29.B int overwrite;
30.PP
31.B void unsetenv(name)
32.B char *name;
c80211f9
KM
33.fi
34.SH DESCRIPTION
4f3c5ada
KB
35\fIGetenv\fP searches the environment list (see \fIenviron\fP(7))
36for a string of the form \fIname\fP\fB=\fP\fIvalue\fP and returns
37a pointer to the string \fIvalue\fP if such a string is present,
38and 0 (NULL) if it is not.
39.PP
40\fISetenv\fP searches the environment list as \fIgetenv\fP does; if
41the string \fIname\fP is not found, a string of the form
42\fIname\fP\fB=\fP\fIvalue\fP is added to the environment. If it is
0125ac17
KB
43found, and \fIoverwrite\fP is non-zero, its value is changed to
44\fIvalue\fP. \fISetenv\fP returns 0 on success and -1 on failure,
45where failure is caused by an inability to allocate space for the
46environment.
4f3c5ada
KB
47.PP
48\fIUnsetenv\fP removes all occurrences of the string \fIname\fP from
0125ac17
KB
49the environment. There is no library provision for completely removing
50the current environment. It is suggested that the following code be
51used to do so.
52.PP
53.nf
54 static char *envinit[1];
55 extern char **environ;
56 environ = envinit;
57.fi
4f3c5ada
KB
58.PP
59All of these routines permit, but do not require, a trailing equals
83296280 60(``='') sign on \fIname\fP or a leading equals sign on \fIvalue\fP.
c80211f9 61.SH SEE ALSO
4f3c5ada 62csh(1), sh(1), execve(2), environ(7)
31b20f0a
KB
63.SH BUGS
64All information is part of the environment, so it must be copied
65if it is to be manipulated.