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: }

Defined functions

_findenv defined in line 36; used 5 times
getenv defined in line 17; used 353 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1987-03-31
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3137
Valid CSS Valid XHTML 1.0 Strict