Annotation of researchv10no/cmd/spitbol/cint/rdenv.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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