Annotation of coherent/d/lib/libc/stdio/finit.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Standard I/O Library Internals
                      3:  * initialize file for I/O
                      4:  *     decide if buffered
                      5:  *     allocate buffer if required
                      6:  *     stuff appropriate get/put functions
                      7:  *     reset char count
                      8:  */
                      9: 
                     10: #include <stdio.h>
                     11: 
                     12: 
                     13: void
                     14: finit(fp)
                     15: register FILE  *fp;
                     16: {
                     17:        register int    tty;
                     18:        extern  int     _fgetc();
                     19:        extern  int     _fputc();
                     20:        extern  int     _fgetb();
                     21:        extern  int     _fputb();
                     22:        extern  int     _fputt();
                     23: 
                     24:        if (fp->_bp == NULL
                     25:         && (fp->_ff&_FSTBUF || (tty=isatty(fileno(fp))) && fp!=stdout
                     26:            || (fp->_bp = malloc(BUFSIZ)) == NULL)) {
                     27:                fp->_gt = &_fgetc;
                     28:                fp->_pt = &_fputc;
                     29:        } else if ((fp->_ff&_FSTBUF)==0 && tty && fp==stdout) {
                     30:                fp->_gt = &_fgetb;
                     31:                fp->_pt = &_fputt;
                     32:                fp->_dp = fp->_cp = fp->_bp;
                     33:                fp->_cc = 0;
                     34:        } else {
                     35:                fp->_gt = &_fgetb;
                     36:                fp->_pt = &_fputb;
                     37:                fp->_dp = fp->_cp = fp->_bp + boffset(fileno(fp));
                     38:                fp->_cc = 0;
                     39:        }
                     40: }
                     41: 
                     42: static
                     43: int
                     44: boffset(fd)
                     45: int    fd;
                     46: {
                     47:        extern  long    lseek();
                     48:        register long   off;
                     49: 
                     50:        if ((off=lseek(fd, 0L, SEEK_CUR))==-1L)
                     51:                return (0);
                     52:        else
                     53:                return ((unsigned)off%BUFSIZ);
                     54: }
                     55: 
                     56: int
                     57: _fginit(fp)
                     58: register FILE  *fp;
                     59: {
                     60:        finit(fp);
                     61:        return ((*fp->_gt)(fp));
                     62: }
                     63: 
                     64: int
                     65: _fpinit(c, fp)
                     66: register char  c;
                     67: register FILE  *fp;
                     68: {
                     69:        finit(fp);
                     70:        return ((*fp->_pt)(c, fp));
                     71: }
                     72: 
                     73: 
                     74: /*
                     75:  * Close all files (called from exit)
                     76:  */
                     77: 
                     78: void
                     79: _finish()
                     80: {
                     81:        register FILE   **fpp;
                     82: 
                     83:        for (fpp = &_fp[_NFILE-1]; fpp>=&_fp[0]; --fpp)
                     84:                if (*fpp!=NULL)
                     85:                        fclose(*fpp);
                     86: }

unix.superglobalmegacorp.com

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