summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/setvbuf.c
blob: ec0f77578af54842454cc989842a6cc216abbe3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "stddef.h" // for NULL

#include <__stdio.h>
#include <stdio.h> // for _IONBF, FILE, _IOFBF, _IOLBF, setvbuf, size_t

int setvbuf(struct __FILE *restrict stream, char *restrict buf, int type, size_t size)
{
	if (type != _IOFBF && type != _IOLBF && type != _IONBF)
		return -1;
	if (type != _IONBF && (buf == NULL || size == 0))
		return -1;

	if (stream->fd < 0)
		return -1;

	stream->buf = buf;
	stream->buf_size = size;
	stream->buf_pos = 0;
	stream->type = type;

	return 0;
}