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