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