Annotation of researchv9/libc/gen/getenv.c, revision 1.1

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

unix.superglobalmegacorp.com

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