outs for programs using alternae memory allocators:
[unix-history] / usr / src / lib / libc / stdio / setbuffer.c
CommitLineData
586c39b1
DF
1/*
2 * Copyright (c) 1983 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
7#ifndef lint
8static char sccsid[] = "@(#)setbuffer.c 5.1 (Berkeley) %G%";
9#endif not lint
10
30b0fd94
KM
11#include <stdio.h>
12
13setbuffer(iop, buf, size)
41e01b3e 14 register FILE *iop;
30b0fd94
KM
15 char *buf;
16 int size;
17{
18 if (iop->_base != NULL && iop->_flag&_IOMYBUF)
19 free(iop->_base);
20 iop->_flag &= ~(_IOMYBUF|_IONBF|_IOLBF);
21 if ((iop->_base = buf) == NULL) {
22 iop->_flag |= _IONBF;
23 iop->_bufsiz = NULL;
24 } else {
25 iop->_ptr = iop->_base;
26 iop->_bufsiz = size;
27 }
28 iop->_cnt = 0;
29}
d5c54585
KM
30
31/*
32 * set line buffering for either stdout or stderr
33 */
34setlinebuf(iop)
41e01b3e 35 register FILE *iop;
d5c54585 36{
8f58e367 37 char *buf;
63b1c981 38 extern char *malloc();
d5c54585 39
d5c54585 40 fflush(iop);
8f58e367
MK
41 setbuffer(iop, NULL, 0);
42 buf = malloc(BUFSIZ);
43 if (buf != NULL) {
44 setbuffer(iop, buf, BUFSIZ);
45 iop->_flag |= _IOLBF|_IOMYBUF;
46 }
d5c54585 47}