161180Sbostic.\" Copyright (c) 1988, 1991, 1993 261180Sbostic.\" The Regents of the University of California. All rights reserved. 320328Smckusick.\" 450303Sbostic.\" This code is derived from software contributed to Berkeley by 550303Sbostic.\" the American National Standards Committee X3, on Information 650303Sbostic.\" Processing Systems. 750303Sbostic.\" 842119Sbostic.\" %sccs.include.redist.man% 935710Sbostic.\" 10*65099Smckusick.\" @(#)getenv.3 8.2 (Berkeley) 12/11/93 1135710Sbostic.\" 1248350Scael.Dd 1348350Scael.Dt GETENV 3 1448350Scael.Os 1548350Scael.Sh NAME 1648350Scael.Nm getenv , 1748350Scael.Nm putenv , 1848350Scael.Nm setenv , 1948350Scael.Nm unsetenv 2048350Scael.Nd environment variable functions 2148350Scael.Sh SYNOPSIS 2248350Scael.Fd #include <stdlib.h> 2348350Scael.Ft char * 2448350Scael.Fn getenv "const char *name" 2548350Scael.Ft int 2648350Scael.Fn setenv "const char *name" "const char *value" "int overwrite" 2748350Scael.Ft int 2848350Scael.Fn putenv "const char *string" 2948350Scael.Ft void 3048350Scael.Fn unsetenv "const char *name" 3148350Scael.Sh DESCRIPTION 3248350ScaelThese functions set, unset and fetch environment variables from the 3348350Scaelhost 3448350Scael.Em environment list . 3548350ScaelFor compatibility with differing environment conventions, 3648350Scaelthe given arguments 3748350Scael.Ar name 3848350Scaeland 3948350Scael.Ar value 4048350Scaelmay be appended and prepended, 4148350Scaelrespectively, 4248350Scaelwith an equal sign 4348350Scael.Dq Li \&= . 4448350Scael.Pp 4548350ScaelThe 4648350Scael.Fn getenv 4748350Scaelfunction obtains the current value of the environment variable, 4848350Scael.Ar name . 4948350ScaelIf the variable 5048350Scael.Ar name 51*65099Smckusickis not in the current environment, 5248350Scaela null pointer is returned. 5348350Scael.Pp 5448350ScaelThe 5548350Scael.Fn setenv 5648350Scaelfunction inserts or resets the environment variable 5748350Scael.Ar name 5848350Scaelin the current environment list. 5948350ScaelIf the variable 6048350Scael.Ar name 6148350Scaeldoes not exist in the list, 6248350Scaelit is inserted with the given 6348350Scael.Ar value. 6448350ScaelIf the variable does exist, the argument 6548350Scael.Ar overwrite 6648350Scaelis tested; if 6748350Scael.Ar overwrite is 6848350Scaelzero, the 6948350Scaelvariable is not reset, otherwise it is reset 7048350Scaelto the given 7148350Scael.Ar value . 7248350Scael.Pp 7348350ScaelThe 7448350Scael.Fn putenv 7551602Sbosticfunction takes an argument of the form ``name=value'' and is 7651602Sbosticequivalent to: 7748350Scael.Bd -literal -offset indent 7842119Sbosticsetenv(name, value, 1); 7948350Scael.Ed 8048350Scael.Pp 8148350ScaelThe 8248350Scael.Fn unsetenv 8348350Scaelfunction 8448350Scaeldeletes all instances of the variable name pointed to by 8548350Scael.Fa name 8648350Scaelfrom the list. 8748350Scael.Sh RETURN VALUES 8848350ScaelThe functions 8948350Scael.Fn setenv 9048350Scaeland 9148350Scael.Fn putenv 9248350Scaelreturn zero if successful; otherwise the global variable 9348350Scael.Va errno 9448350Scaelis set to indicate the error and a 9548350Scael\-1 is returned. 9648350Scael.Sh ERRORS 9748350Scael.Bl -tag -width [ENOMEM] 9848350Scael.It Bq Er ENOMEM 9948350ScaelThe function 10048350Scael.Fn setenv 10142119Sbosticor 10248350Scael.Fn putenv 10342119Sbosticfailed because they were unable to allocate memory for the environment. 10448350Scael.El 10548350Scael.Sh SEE ALSO 10648350Scael.Xr csh 1 , 10748350Scael.Xr sh 1 , 10848350Scael.Xr execve 2 , 10948350Scael.Xr environ 7 11048350Scael.Sh STANDARDS 11148350ScaelThe 11248350Scael.Fn getenv 11348350Scaelfunction conforms to 11448350Scael.St -ansiC . 11548350Scael.Sh HISTORY 11648350ScaelThe functions 11748350Scael.Fn setenv 11848350Scaeland 11948350Scael.Fn unsetenv 12048350Scaelappeared in 12148350Scael.At v7 . 12248350ScaelThe 12348350Scael.Fn putenv 12448350Scaelfunction appeared in 12548350Scael.Bx 4.3 Reno . 126