|
|
1.1 ! root 1: /* ! 2: * libc/stdio/_finit.c ! 3: * ANSI-compliant C standard i/o library internals. ! 4: * _fginit(), _fpinit() ! 5: * Initialize file for i/o. ! 6: */ ! 7: ! 8: #include <stdio.h> ! 9: #include <errno.h> ! 10: ! 11: /* ! 12: * The get and put function pointers in a FILE ! 13: * initially contain &_fginit and &_fpinit. ! 14: * The first get/put on the stream calls _f[gp]init() ! 15: * which calls finit(). ! 16: * finit() calls setvbuf() to initialize stream buffering ! 17: * and to reset the get and put functions appropriately. ! 18: */ ! 19: static ! 20: void ! 21: finit(stream) register FILE *stream; ! 22: { ! 23: register int mode, sav; ! 24: ! 25: if (stream->_mode != _MODE_UNINIT) ! 26: return; /* setvbuf already called */ ! 27: sav = errno; /* because isatty() can set errno */ ! 28: mode = (isatty(fileno(stream)) && stream==stdout) ? _IOLBF : _IOFBF; ! 29: if (setvbuf(stream, NULL, mode, (size_t)BUFSIZ) == 0) ! 30: return; /* buffered or line buffered */ ! 31: setvbuf(stream, NULL, _IONBF, (size_t)0); /* unbuffered */ ! 32: errno = sav; ! 33: } ! 34: ! 35: /* ! 36: * Initialize and get. ! 37: */ ! 38: int ! 39: _fginit(stream) register FILE *stream; ! 40: { ! 41: finit(stream); ! 42: return (*stream->_f2p->_gt)(stream); ! 43: } ! 44: ! 45: /* ! 46: * Initialize and put. ! 47: */ ! 48: int ! 49: _fpinit(c, stream) register char c; register FILE *stream; ! 50: { ! 51: finit(stream); ! 52: return (*stream->_f2p->_pt)(c, stream); ! 53: } ! 54: ! 55: /* end of libc/stdio/_finit.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.