1.\" Copyright (c) 1988, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the American National Standards Committee X3, on Information 6.\" Processing Systems. 7.\" 8.\" %sccs.include.redist.man% 9.\" 10.\" @(#)getenv.3 6.11 (Berkeley) 06/29/91 11.\" 12.Dd 13.Dt GETENV 3 14.Os 15.Sh NAME 16.Nm getenv , 17.Nm putenv , 18.Nm setenv , 19.Nm unsetenv 20.Nd environment variable functions 21.Sh SYNOPSIS 22.Fd #include <stdlib.h> 23.Ft char * 24.Fn getenv "const char *name" 25.Ft int 26.Fn setenv "const char *name" "const char *value" "int overwrite" 27.Ft int 28.Fn putenv "const char *string" 29.Ft void 30.Fn unsetenv "const char *name" 31.Sh DESCRIPTION 32These functions set, unset and fetch environment variables from the 33host 34.Em environment list . 35For compatibility with differing environment conventions, 36the given arguments 37.Ar name 38and 39.Ar value 40may be appended and prepended, 41respectively, 42with an equal sign 43.Dq Li \&= . 44.Pp 45The 46.Fn getenv 47function obtains the current value of the environment variable, 48.Ar name . 49If the variable 50.Ar name 51is not in the current environment , 52a null pointer is returned. 53.Pp 54The 55.Fn setenv 56function inserts or resets the environment variable 57.Ar name 58in the current environment list. 59If the variable 60.Ar name 61does not exist in the list, 62it is inserted with the given 63.Ar value. 64If the variable does exist, the argument 65.Ar overwrite 66is tested; if 67.Ar overwrite is 68zero, the 69variable is not reset, otherwise it is reset 70to the given 71.Ar value . 72.Pp 73The 74.Fn putenv 75function 76performs the equivalent of: 77.Bd -literal -offset indent 78setenv(name, value, 1); 79.Ed 80.Pp 81The 82.Fn unsetenv 83function 84deletes all instances of the variable name pointed to by 85.Fa name 86from the list. 87.Sh RETURN VALUES 88The functions 89.Fn setenv 90and 91.Fn putenv 92return zero if successful; otherwise the global variable 93.Va errno 94is set to indicate the error and a 95\-1 is returned. 96.Sh ERRORS 97.Bl -tag -width [ENOMEM] 98.It Bq Er ENOMEM 99The function 100.Fn setenv 101or 102.Fn putenv 103failed because they were unable to allocate memory for the environment. 104.El 105.Sh SEE ALSO 106.Xr csh 1 , 107.Xr sh 1 , 108.Xr execve 2 , 109.Xr environ 7 110.Sh STANDARDS 111The 112.Fn getenv 113function conforms to 114.St -ansiC . 115.Sh HISTORY 116The functions 117.Fn setenv 118and 119.Fn unsetenv 120appeared in 121.At v7 . 122The 123.Fn putenv 124function appeared in 125.Bx 4.3 Reno . 126