Annotation of researchv10no/libc/gen/strtol.c, revision 1.1.1.1

1.1       root        1: #include <errno.h>
                      2: #include <ctype.h>
                      3: 
                      4: #define T_LONG_MAX (long)(~(unsigned long)0>>1)
                      5: #define T_LONG_MIN (~T_LONG_MAX)
                      6: #define POS 0
                      7: extern unsigned long strtoul();
                      8: 
                      9: long
                     10: strtol(iptr, endptr, base)
                     11: char *iptr;
                     12: register char **endptr;
                     13: {
                     14:        register char *nptr = iptr;
                     15:        register sign = POS;
                     16:        register long result;
                     17: 
                     18:        if(endptr)
                     19:                *endptr = iptr;
                     20:        while(isspace(*nptr))
                     21:                nptr++;
                     22:        switch(*nptr) {
                     23:        case '-':
                     24:                sign = !POS;
                     25:        case '+':
                     26:                nptr++;
                     27:        }
                     28:        if(!isalnum(*nptr))
                     29:                return 0;
                     30:        result = (long)strtoul(nptr, &iptr, base);
                     31:        if(endptr && iptr!=nptr)
                     32:                *endptr = iptr;
                     33:        if(result < 0) {
                     34:                if(sign==POS || result!=T_LONG_MIN)
                     35:                        errno = ERANGE;
                     36:                return sign==POS? T_LONG_MAX: T_LONG_MIN;
                     37:        }
                     38:        return sign==POS? result: -result;
                     39: }

unix.superglobalmegacorp.com

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