home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixlib36d
/
src
/
stdio
/
c
/
flsbuf
< prev
next >
Wrap
Text File
|
1994-03-08
|
1KB
|
63 lines
static char sccs_id[] = "@(#) flsbuf.c 4.1 " __DATE__ " HJR";
/* flsbuf.c (c) Copyright 1990 H.Rogers */
#include <stdlib.h>
#include <stdio.h>
#include "fcntl.h"
extern int write (int, void *, int);
__STDIOLIB__
/* __flsbuf(-1,f) flushes output without adding c */
int
__flsbuf (register int c, register FILE * f)
{
register int n, b, g = f->flag;
register unsigned char *a, *p;
if ((g & (_IOWRITE | _IOERR | _IOEOF)) != _IOWRITE)
return (-1);
b = (g & _IONBF) ? 1 : f->bufsiz;
if (!(a = f->o_base))
{
if (!(a = f->o_base = malloc (b)))
{
f->flag = g | _IOERR;
return (-1);
}
if (b > 1 && c >= 0 && !(c == '\n' && (g & _IOLBF)))
{
f->o_cnt = b - 1;
f->o_ptr = a + 1;
return (*a = c);
}
p = f->o_ptr = a;
}
else
p = f->o_ptr;
if (c >= 0)
*p++ = c;
n = p - a;
if (n > 0)
if (write (f->fd, a, n) < n)
{
f->flag = g | _IOERR;
return (-1);
}
f->pos += n;
f->o_cnt = b;
f->o_ptr = a;
return ((c >= 0) ? c : 0);
}