install C version of _doprnt
[unix-history] / usr / src / lib / libc / stdio / fwrite.c
CommitLineData
586c39b1
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
2ce81398
DS
7#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)fwrite.c 5.2 (Berkeley) %G%";
9#endif LIBC_SCCS and not lint
586c39b1 10
29468241
MK
11#include <stdio.h>
12
13fwrite(ptr, size, count, iop)
14 register char *ptr;
15 unsigned size, count;
16 register FILE *iop;
17{
18 register int s;
19
20 s = size * count;
6104f3ac 21 if (iop->_flag & _IOLBF)
0ece7e53 22 while (s > 0) {
6104f3ac
RC
23 if (--iop->_cnt > -iop->_bufsiz && *ptr != '\n')
24 *iop->_ptr++ = *ptr++;
25 else if (_flsbuf(*(unsigned char *)ptr++, iop) == EOF)
26 break;
0ece7e53 27 s--;
6104f3ac
RC
28 }
29 else while (s > 0) {
29468241
MK
30 if (iop->_cnt < s) {
31 if (iop->_cnt > 0) {
32 bcopy(ptr, iop->_ptr, iop->_cnt);
33 ptr += iop->_cnt;
34 iop->_ptr += iop->_cnt;
35 s -= iop->_cnt;
36 }
6104f3ac 37 if (_flsbuf(*(unsigned char *)ptr++, iop) == EOF)
29468241
MK
38 break;
39 s--;
40 }
41 if (iop->_cnt >= s) {
42 bcopy(ptr, iop->_ptr, s);
43 iop->_ptr += s;
44 iop->_cnt -= s;
45 return (count);
46 }
47 }
a2dc047f 48 return (size != 0 ? count - ((s + size - 1) / size) : 0);
29468241 49}