• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "stdio_impl.h"
2 
3 /* The behavior of this function is undefined except when it is the first
4  * operation on the stream, so the presence or absence of locking is not
5  * observable in a program whose behavior is defined. Thus no locking is
6  * performed here. No allocation of buffers is performed, but a buffer
7  * provided by the caller is used as long as it is suitably sized. */
8 
setvbuf(FILE * restrict f,char * restrict buf,int type,size_t size)9 int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size)
10 {
11 	f->lbf = EOF;
12 
13 	if (type == _IONBF) {
14 		f->buf_size = 0;
15 		f->flags |= F_NOBUF;
16 	} else if (type == _IOLBF || type == _IOFBF) {
17 		if (buf && size >= UNGET) {
18 			f->buf = (void *)(buf + UNGET);
19 			f->buf_size = size - UNGET;
20 		}
21 		if (type == _IOLBF && f->buf_size)
22 			f->lbf = '\n';
23 		f->flags &= ~F_NOBUF;
24 	} else {
25 		return -1;
26 	}
27 
28 	f->flags |= F_SVB;
29 
30 	return 0;
31 }
32