|
|
1.1 root 1: /* <@(#)fputs.c 3.5> */
2: /*LINTLIBRARY*/
3: /*
4: * This version writes directly to the buffer rather than looping on putc.
5: * Ptr args aren't checked for NULL because the program would be a
6: * catastrophic mess anyway. Better to abort than just to return NULL.
7: */
8: #include <stdio.h>
9: #include "stdiom.h"
10:
11: extern char *memccpy();
12:
13: int
14: fputs(ptr, iop)
15: char *ptr;
16: register FILE *iop;
17: {
18: register int ndone = 0, n;
19: register unsigned char *cptr, *bufend;
20: char *p;
21:
22: if (_WRTCHK(iop))
23: return (0);
24: bufend = _bufend(iop);
25:
26: if ((iop->_flag & _IONBF) == 0) {
27: for ( ; ; ptr += n) {
28: while ((n = bufend - (cptr = iop->_ptr)) <= 0)
29: /* full buf */
30: if (_xflsbuf(iop) == EOF)
31: return(EOF);
32: if ((p = memccpy((char *) cptr, ptr, '\0', n)) != NULL)
33: n = (p - (char *) cptr) - 1;
34: iop->_cnt -= n;
35: iop->_ptr += n;
36: _BUFSYNC(iop);
37: ndone += n;
38: if (p != NULL) {
39: /* done; flush buffer if line-buffered */
40: if (iop->_flag & _IOLBF)
41: if (_xflsbuf(iop) == EOF)
42: return(EOF);
43: return(ndone);
44: }
45: }
46: } else {
47: /* write out to an unbuffered file */
48: register unsigned int cnt = strlen(ptr);
49:
50: (void)write(iop->_file, ptr, cnt);
51: return cnt;
52: }
53: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.