2 * setbuf.c - control buffering of a stream
10 extern void (*_clean
)(void);
13 setvbuf(register FILE *stream
, char *buf
, int mode
, size_t size
)
18 if (mode
!= _IOFBF
&& mode
!= _IOLBF
&& mode
!= _IONBF
)
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
) {
31 stream
->_flags
|= _IOMYBUF
;
35 stream
->_buf
= (unsigned char *) buf
;
38 stream
->_flags
|= mode
;
39 stream
->_ptr
= stream
->_buf
;
44 stream
->_bufsiz
= size
;