Annotation of researchv10no/cmd/spitbol/rdenv.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     rdenv ( varname, result ) - read the environment variable named
        !             3:  *             "varname", and if it can be read, put its value in "result"
        !             4:  *             return 0 on success, -1 on failure
        !             5:  */
        !             6: 
        !             7: #include "spitblks.h"
        !             8: 
        !             9: /* the environment pointer */
        !            10: extern char **environ;
        !            11: 
        !            12: rdenv ( varname, result )
        !            13:        register struct scblk *varname, *result;
        !            14: {
        !            15:        register n;
        !            16:        register char *p, *q, **env;
        !            17: 
        !            18:        /* one iteration per environment variable */
        !            19:        env = environ;
        !            20:        while ( p = *env ) {
        !            21:                q = varname -> str;
        !            22:                n = varname -> len;
        !            23: 
        !            24:                /* match the variable against the environment */
        !            25:                while ( n > 0 && *p == *q && *p != '\0' && *p != '=' ) {
        !            26:                        p++;
        !            27:                        q++;
        !            28:                        n--;
        !            29:                }
        !            30: 
        !            31:                /* if successful, copy result and return */
        !            32:                if ( *p == '=' && n == 0 ) {
        !            33:                        p++;
        !            34:                        q = result -> str;
        !            35:                        while ( *p != '\0' && n < result -> len ) {
        !            36:                                *q++ = *p++;
        !            37:                                n++;
        !            38:                        }
        !            39:                        result -> len = n;
        !            40:                        return 0;
        !            41:                }
        !            42: 
        !            43:                env++;
        !            44:        }
        !            45: 
        !            46:        return -1;
        !            47: }

unix.superglobalmegacorp.com

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