setvbuf: return failure if mode is invalid
POSIX requires setvbuf to return non-zero if `mode` is not one of _IONBF,
_IOLBF, or _IOFBF.
diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c
index 06ea296..523dddc 100644
--- a/src/stdio/setvbuf.c
+++ b/src/stdio/setvbuf.c
@@ -12,13 +12,15 @@
if (type == _IONBF) {
f->buf_size = 0;
- } else {
+ } else if (type == _IOLBF || type == _IOFBF) {
if (buf && size >= UNGET) {
f->buf = (void *)(buf + UNGET);
f->buf_size = size - UNGET;
}
if (type == _IOLBF && f->buf_size)
f->lbf = '\n';
+ } else {
+ return -1;
}
f->flags |= F_SVB;