|
|
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))) ? _IOFBF
29: : (stream == stdout) ? _IOLBF : _IONBF;
30: if (setvbuf(stream, NULL, mode, (size_t)BUFSIZ) == 0)
31: return; /* buffered or line buffered */
32: setvbuf(stream, NULL, _IONBF, (size_t)0); /* unbuffered */
33: errno = sav;
34: }
35:
36: /*
37: * Initialize and get.
38: */
39: int
40: _fginit(stream) register FILE *stream;
41: {
42: finit(stream);
43: return (*stream->_f2p->_gt)(stream);
44: }
45:
46: /*
47: * Initialize and put.
48: */
49: int
50: _fpinit(c, stream) register char c; register FILE *stream;
51: {
52: finit(stream);
53: return (*stream->_f2p->_pt)(c, stream);
54: }
55:
56: /* 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.