1*48350Scael.\" Copyright (c) 1988, 1991 The Regents of the University of California. 235710Sbostic.\" All rights reserved. 320328Smckusick.\" 442119Sbostic.\" %sccs.include.redist.man% 535710Sbostic.\" 6*48350Scael.\" @(#)getenv.3 6.10 (Berkeley) 04/19/91 735710Sbostic.\" 8*48350Scael.Dd 9*48350Scael.Dt GETENV 3 10*48350Scael.Os 11*48350Scael.Sh NAME 12*48350Scael.Nm getenv , 13*48350Scael.Nm putenv , 14*48350Scael.Nm setenv , 15*48350Scael.Nm unsetenv 16*48350Scael.Nd environment variable functions 17*48350Scael.Sh SYNOPSIS 18*48350Scael.Fd #include <stdlib.h> 19*48350Scael.Ft char * 20*48350Scael.Fn getenv "const char *name" 21*48350Scael.Ft int 22*48350Scael.Fn setenv "const char *name" "const char *value" "int overwrite" 23*48350Scael.Ft int 24*48350Scael.Fn putenv "const char *string" 25*48350Scael.Ft void 26*48350Scael.Fn unsetenv "const char *name" 27*48350Scael.Sh DESCRIPTION 28*48350ScaelThese functions set, unset and fetch environment variables from the 29*48350Scaelhost 30*48350Scael.Em environment list . 31*48350ScaelFor compatibility with differing environment conventions, 32*48350Scaelthe given arguments 33*48350Scael.Ar name 34*48350Scaeland 35*48350Scael.Ar value 36*48350Scaelmay be appended and prepended, 37*48350Scaelrespectively, 38*48350Scaelwith an equal sign 39*48350Scael.Dq Li \&= . 40*48350Scael.Pp 41*48350ScaelThe 42*48350Scael.Fn getenv 43*48350Scaelfunction obtains the current value of the environment variable, 44*48350Scael.Ar name . 45*48350ScaelIf the variable 46*48350Scael.Ar name 47*48350Scaelis not in the current environment , 48*48350Scaela null pointer is returned. 49*48350Scael.Pp 50*48350ScaelThe 51*48350Scael.Fn setenv 52*48350Scaelfunction inserts or resets the environment variable 53*48350Scael.Ar name 54*48350Scaelin the current environment list. 55*48350ScaelIf the variable 56*48350Scael.Ar name 57*48350Scaeldoes not exist in the list, 58*48350Scaelit is inserted with the given 59*48350Scael.Ar value. 60*48350ScaelIf the variable does exist, the argument 61*48350Scael.Ar overwrite 62*48350Scaelis tested; if 63*48350Scael.Ar overwrite is 64*48350Scaelzero, the 65*48350Scaelvariable is not reset, otherwise it is reset 66*48350Scaelto the given 67*48350Scael.Ar value . 68*48350Scael.Pp 69*48350ScaelThe 70*48350Scael.Fn putenv 71*48350Scaelfunction 72*48350Scaelperforms the equivalent of: 73*48350Scael.Bd -literal -offset indent 7442119Sbosticsetenv(name, value, 1); 75*48350Scael.Ed 76*48350Scael.Pp 77*48350ScaelThe 78*48350Scael.Fn unsetenv 79*48350Scaelfunction 80*48350Scaeldeletes all instances of the variable name pointed to by 81*48350Scael.Fa name 82*48350Scaelfrom the list. 83*48350Scael.Sh RETURN VALUES 84*48350ScaelThe functions 85*48350Scael.Fn setenv 86*48350Scaeland 87*48350Scael.Fn putenv 88*48350Scaelreturn zero if successful; otherwise the global variable 89*48350Scael.Va errno 90*48350Scaelis set to indicate the error and a 91*48350Scael\-1 is returned. 92*48350Scael.Sh ERRORS 93*48350Scael.Bl -tag -width [ENOMEM] 94*48350Scael.It Bq Er ENOMEM 95*48350ScaelThe function 96*48350Scael.Fn setenv 9742119Sbosticor 98*48350Scael.Fn putenv 9942119Sbosticfailed because they were unable to allocate memory for the environment. 100*48350Scael.El 101*48350Scael.Sh SEE ALSO 102*48350Scael.Xr csh 1 , 103*48350Scael.Xr sh 1 , 104*48350Scael.Xr execve 2 , 105*48350Scael.Xr environ 7 106*48350Scael.Sh STANDARDS 107*48350ScaelThe 108*48350Scael.Fn getenv 109*48350Scaelfunction conforms to 110*48350Scael.St -ansiC . 111*48350Scael.Sh HISTORY 112*48350ScaelThe functions 113*48350Scael.Fn setenv 114*48350Scaeland 115*48350Scael.Fn unsetenv 116*48350Scaelappeared in 117*48350Scael.At v7 . 118*48350ScaelThe 119*48350Scael.Fn putenv 120*48350Scaelfunction appeared in 121*48350Scael.Bx 4.3 Reno . 122