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