Annotation of researchv10dc/libc/stdio/fgets.c, revision 1.1.1.1

1.1       root        1: /* Copyright AT&T Bell Laboratories, 1993 */
                      2: #include       <stdio.h>
                      3: 
                      4: char *
                      5: fgets(char *ptr, int n, FILE *iop)
                      6: {
                      7:        int l = 0;
                      8:        char *s = ptr;
                      9:        unsigned char *t;
                     10:        while(--n > 0) {
                     11:                l = iop->_cnt;
                     12:                if(l > 0) {
                     13:                        if(l > n) l = n;
                     14:                        t = iop->_ptr;
                     15:                        while(--l >= 0 && (*s++ = *t++) != '\n')
                     16:                                continue;
                     17:                        l = t - iop->_ptr;
                     18:                        iop->_ptr = t;
                     19:                        iop->_cnt -= l;
                     20:                        if(t[-1] == '\n' || (n -= l) <= 0)
                     21:                                break;
                     22:                }
                     23:                l = getc(iop);
                     24:                if(l == EOF)
                     25:                        break;
                     26:                *s++ = l;
                     27:                if(l == '\n')
                     28:                        break;
                     29:        }
                     30:        *s = 0;
                     31:        return l<0 && s==ptr? 0: ptr;
                     32: }

unix.superglobalmegacorp.com

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