Uninitialized vector entry?
[minix3.git] / lib / stdio / setvbuf.c
blob2c5e769dff9794352849cb112a27728cfa052b17
1 /*
2 * setbuf.c - control buffering of a stream
3 */
4 /* $Id$ */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "loc_incl.h"
10 extern void (*_clean)(void);
12 int
13 setvbuf(register FILE *stream, char *buf, int mode, size_t size)
15 int retval = 0;
17 _clean = __cleanup;
18 if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF)
19 return EOF;
21 if (stream->_buf && io_testflag(stream,_IOMYBUF) )
22 free((void *)stream->_buf);
24 stream->_flags &= ~(_IOMYBUF | _IONBF | _IOLBF);
26 if (buf && size <= 0) retval = EOF;
27 if (!buf && (mode != _IONBF)) {
28 if (size <= 0 || (buf = (char *) malloc(size)) == NULL) {
29 retval = EOF;
30 } else {
31 stream->_flags |= _IOMYBUF;
35 stream->_buf = (unsigned char *) buf;
37 stream->_count = 0;
38 stream->_flags |= mode;
39 stream->_ptr = stream->_buf;
41 if (!buf) {
42 stream->_bufsiz = 1;
43 } else {
44 stream->_bufsiz = size;
47 return retval;