Annotation of 43BSD/lib/libc/gen/getenv.c, revision 1.1.1.1

1.1       root        1: #if defined(LIBC_SCCS) && !defined(lint)
                      2: static char sccsid[] = "@(#)getenv.c   5.2 (Berkeley) 3/9/86";
                      3: #endif LIBC_SCCS and not lint
                      4: 
                      5: /*
                      6:  *     getenv(name)
                      7:  *     returns ptr to value associated with name, if any, else NULL
                      8:  */
                      9: #define NULL   0
                     10: extern char **environ;
                     11: char   *nvmatch();
                     12: 
                     13: char *
                     14: getenv(name)
                     15: register char *name;
                     16: {
                     17:        register char **p = environ;
                     18:        register char *v;
                     19: 
                     20:        while (*p != NULL)
                     21:                if ((v = nvmatch(name, *p++)) != NULL)
                     22:                        return(v);
                     23:        return(NULL);
                     24: }
                     25: 
                     26: /*
                     27:  *     s1 is either name, or name=value
                     28:  *     s2 is name=value
                     29:  *     if names match, return value of s2, else NULL
                     30:  *     used for environment searching: see getenv
                     31:  */
                     32: 
                     33: static char *
                     34: nvmatch(s1, s2)
                     35: register char *s1, *s2;
                     36: {
                     37: 
                     38:        while (*s1 == *s2++)
                     39:                if (*s1++ == '=')
                     40:                        return(s2);
                     41:        if (*s1 == '\0' && *(s2-1) == '=')
                     42:                return(s2);
                     43:        return(NULL);
                     44: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.