xref: /csrg-svn/lib/libc/stdio/setbuffer.c (revision 21410)
1*21410Sdist /*
2*21410Sdist  * Copyright (c) 1983 Regents of the University of California.
3*21410Sdist  * All rights reserved.  The Berkeley software License Agreement
4*21410Sdist  * specifies the terms and conditions for redistribution.
5*21410Sdist  */
6*21410Sdist 
7*21410Sdist #ifndef lint
8*21410Sdist static char sccsid[] = "@(#)setbuffer.c	5.1 (Berkeley) 05/30/85";
9*21410Sdist #endif not lint
10*21410Sdist 
118327Smckusick #include	<stdio.h>
128327Smckusick 
138327Smckusick setbuffer(iop, buf, size)
1417951Sserge 	register FILE *iop;
158327Smckusick 	char *buf;
168327Smckusick 	int size;
178327Smckusick {
188327Smckusick 	if (iop->_base != NULL && iop->_flag&_IOMYBUF)
198327Smckusick 		free(iop->_base);
208327Smckusick 	iop->_flag &= ~(_IOMYBUF|_IONBF|_IOLBF);
218327Smckusick 	if ((iop->_base = buf) == NULL) {
228327Smckusick 		iop->_flag |= _IONBF;
238327Smckusick 		iop->_bufsiz = NULL;
248327Smckusick 	} else {
258327Smckusick 		iop->_ptr = iop->_base;
268327Smckusick 		iop->_bufsiz = size;
278327Smckusick 	}
288327Smckusick 	iop->_cnt = 0;
298327Smckusick }
3011307Smckusick 
3111307Smckusick /*
3211307Smckusick  * set line buffering for either stdout or stderr
3311307Smckusick  */
3411307Smckusick setlinebuf(iop)
3517951Sserge 	register FILE *iop;
3611307Smckusick {
3716522Skarels 	char *buf;
3816491Sralph 	extern char *malloc();
3911307Smckusick 
4011307Smckusick 	fflush(iop);
4116522Skarels 	setbuffer(iop, NULL, 0);
4216522Skarels 	buf = malloc(BUFSIZ);
4316522Skarels 	if (buf != NULL) {
4416522Skarels 		setbuffer(iop, buf, BUFSIZ);
4516522Skarels 		iop->_flag |= _IOLBF|_IOMYBUF;
4616522Skarels 	}
4711307Smckusick }
48