Added option to build for amiga-m68k
[AROS.git] / compiler / stdc / setvbuf.c
blob779b12c2d21da14a90c10c103d53f6badcb662b7
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function setvbuf().
6 */
7 #include <dos/stdio.h>
8 #include <proto/dos.h>
9 #include <errno.h>
11 #include "__stdio.h"
13 /*****************************************************************************
15 NAME */
16 #include <stdio.h>
18 int setvbuf (
20 /* SYNOPSIS */
21 FILE *stream,
22 char *buf,
23 int mode,
24 size_t size)
26 /* FUNCTION
27 Sets the buffer and the mode associated with a stream.
29 INPUTS
30 stream: stream to set buffer on
31 buf: the buffer to be associated, when NULL a buffer will be allocated
32 and freed on close or new setvbuf. Should be longword aligned.
33 mode: mode for buffering
34 - _IOFBF: fully buffered
35 - _IOLBF: line buffered
36 - _IONBF: Not buffered
37 size: size of the buffer (needs to be at least 208).
39 RESULT
40 0 on succes, EOF on error. errno indicated error.
41 Function fails when size < 208 and buf != NULL.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
51 INTERNALS
53 ******************************************************************************/
55 if (!stream)
57 errno = EINVAL;
58 return EOF;
61 /* Pointer has to be longword aligned */
62 if (buf && (((IPTR)buf & 3) != (IPTR)0))
64 char *buf2 = (char *)(((IPTR)buf | 3) + 1);
65 size -= buf2 - buf;
66 buf = buf2;
68 /* Size >= 208 */
69 if (size < 208)
71 if (buf == NULL)
72 size = 208;
73 else
74 errno = EINVAL;
75 return EOF;
78 switch (mode)
80 case _IOFBF:
81 mode = BUF_FULL;
82 break;
83 case _IOLBF:
84 mode = BUF_LINE;
85 break;
86 case _IONBF:
87 mode = BUF_NONE;
88 break;
89 default:
90 errno = EINVAL;
91 return EOF;
94 return SetVBuf(stream->fh, buf, mode, size ? size : -1);
95 } /* setvbuf */