source: trunk/minix/lib/stdio/setvbuf.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 930 bytes
Line 
1/*
2 * setbuf.c - control buffering of a stream
3 */
4/* $Id: setvbuf.c,v 1.1.1.1 2005/04/21 14:56:36 beng Exp $ */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include "loc_incl.h"
9
10extern void (*_clean)(void);
11
12int
13setvbuf(register FILE *stream, char *buf, int mode, size_t size)
14{
15 int retval = 0;
16
17 _clean = __cleanup;
18 if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF)
19 return EOF;
20
21 if (stream->_buf && io_testflag(stream,_IOMYBUF) )
22 free((void *)stream->_buf);
23
24 stream->_flags &= ~(_IOMYBUF | _IONBF | _IOLBF);
25
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;
32 }
33 }
34
35 stream->_buf = (unsigned char *) buf;
36
37 stream->_count = 0;
38 stream->_flags |= mode;
39 stream->_ptr = stream->_buf;
40
41 if (!buf) {
42 stream->_bufsiz = 1;
43 } else {
44 stream->_bufsiz = size;
45 }
46
47 return retval;
48}
Note: See TracBrowser for help on using the repository browser.