home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixlib36d
/
src
/
stdio
/
c
/
setbuf
< prev
next >
Wrap
Text File
|
1994-03-08
|
800b
|
44 lines
static char sccs_id[] = "@(#) setbuf.c 2.0 " __DATE__ " HJR";
/* setbuf.c (c) Copyright 1990 H.Rogers */
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
__STDIOLIB__
void
setbuf (register FILE * f, char *buf)
{
if (!buf)
setvbuf (f, 0, _IONBF, 0);
else
setvbuf (f, buf, _IOFBF, BUFSIZ);
}
int
setvbuf (register FILE * f, register char *buf, register int flag,
register size_t bufsiz)
{
if (f->flag & _IOREAD)
{
if (f->i_base)
return (-1);
f->i_ptr = f->i_base = (unsigned char *) buf;
}
else if (f->flag & _IOWRITE)
{
if (f->o_base)
return (-1);
f->o_ptr = f->o_base = (unsigned char *) buf;
}
else
return (-1);
f->bufsiz = (!bufsiz) ? 1 : bufsiz;
f->flag = (f->flag & (~_IOBF)) | (flag & _IOBF);
return (0);
}