1 /* @(#)fwrite.c 4.3 (Berkeley) 11/29/84 */ 2 #include <stdio.h> 3 4 fwrite(ptr, size, count, iop) 5 register char *ptr; 6 unsigned size, count; 7 register FILE *iop; 8 { 9 register int s; 10 11 s = size * count; 12 if (iop->_flag & _IOLBF) 13 while (--s >= 0) { 14 if (--iop->_cnt > -iop->_bufsiz && *ptr != '\n') 15 *iop->_ptr++ = *ptr++; 16 else if (_flsbuf(*(unsigned char *)ptr++, iop) == EOF) 17 break; 18 } 19 else while (s > 0) { 20 if (iop->_cnt < s) { 21 if (iop->_cnt > 0) { 22 bcopy(ptr, iop->_ptr, iop->_cnt); 23 ptr += iop->_cnt; 24 iop->_ptr += iop->_cnt; 25 s -= iop->_cnt; 26 } 27 if (_flsbuf(*(unsigned char *)ptr++, iop) == EOF) 28 break; 29 s--; 30 } 31 if (iop->_cnt >= s) { 32 bcopy(ptr, iop->_ptr, s); 33 iop->_ptr += s; 34 iop->_cnt -= s; 35 return (count); 36 } 37 } 38 return (count - ((s + size - 1) / size)); 39 } 40