xref: /csrg-svn/lib/libc/stdio/setbuffer.c (revision 26661)
121410Sdist /*
221410Sdist  * Copyright (c) 1983 Regents of the University of California.
321410Sdist  * All rights reserved.  The Berkeley software License Agreement
421410Sdist  * specifies the terms and conditions for redistribution.
521410Sdist  */
621410Sdist 
7*26661Sdonn #if defined(LIBC_SCCS) && !defined(lint)
8*26661Sdonn static char sccsid[] = "@(#)setbuffer.c	5.2 (Berkeley) 03/09/86";
9*26661Sdonn #endif LIBC_SCCS and not lint
1021410Sdist 
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