1 #if defined(LIBC_SCCS) && !defined(lint) 2 static char sccsid[] = "@(#)getenv.c 5.3 (Berkeley) 03/11/87"; 3 #endif LIBC_SCCS and not lint 4 5 #include <stdio.h> 6 7 /* 8 * getenv(name) -- 9 * Returns ptr to value associated with name, if any, else NULL. 10 */ 11 char * 12 getenv(name) 13 char *name; 14 { 15 int offset; 16 char *_findenv(); 17 18 return(_findenv(name,&offset)); 19 } 20 21 /* 22 * _findenv(name,offset) -- 23 * Returns pointer to value associated with name, if any, else NULL. 24 * Sets offset to be the offset of the name/value combination in the 25 * environmental array, for use by setenv(3) and unsetenv(3). 26 * Explicitly removes '=' in argument name. 27 * 28 * This routine *should* be a static; don't use it. 29 */ 30 char * 31 _findenv(name,offset) 32 register char *name; 33 int *offset; 34 { 35 extern char **environ; 36 register int len; 37 register char **P, 38 *C; 39 40 for (C = name,len = 0;*C && *C != '=';++C,++len); 41 for (P = environ;*P;++P) 42 if (!strncmp(*P,name,len)) 43 if (*(C = *P + len) == '=') { 44 *offset = P - environ; 45 return(++C); 46 } 47 return(NULL); 48 } 49