mirror of
https://git.musl-libc.org/git/musl
synced 2025-01-23 06:32:05 +03:00
setvbuf: return failure if mode is invalid
POSIX requires setvbuf to return non-zero if `mode` is not one of _IONBF, _IOLBF, or _IOFBF.
This commit is contained in:
parent
f368d9fd26
commit
00d3d577ca
@ -12,13 +12,15 @@ int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size)
|
|||||||
|
|
||||||
if (type == _IONBF) {
|
if (type == _IONBF) {
|
||||||
f->buf_size = 0;
|
f->buf_size = 0;
|
||||||
} else {
|
} else if (type == _IOLBF || type == _IOFBF) {
|
||||||
if (buf && size >= UNGET) {
|
if (buf && size >= UNGET) {
|
||||||
f->buf = (void *)(buf + UNGET);
|
f->buf = (void *)(buf + UNGET);
|
||||||
f->buf_size = size - UNGET;
|
f->buf_size = size - UNGET;
|
||||||
}
|
}
|
||||||
if (type == _IOLBF && f->buf_size)
|
if (type == _IOLBF && f->buf_size)
|
||||||
f->lbf = '\n';
|
f->lbf = '\n';
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
f->flags |= F_SVB;
|
f->flags |= F_SVB;
|
||||||
|
Loading…
Reference in New Issue
Block a user