mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] setvbuf: return failure if mode is invalid
@ 2019-03-12 20:31 A. Wilcox
  2019-03-13  0:32 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: A. Wilcox @ 2019-03-12 20:31 UTC (permalink / raw)
  To: musl; +Cc: A. Wilcox

POSIX requires setvbuf to return non-zero if `mode` is not one of _IONBF,
_IOLBF, or _IOFBF.
---
 src/stdio/setvbuf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c
index 06ea296c..523dddc8 100644
--- a/src/stdio/setvbuf.c
+++ b/src/stdio/setvbuf.c
@@ -12,13 +12,15 @@ int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size)
 
 	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;
-- 
2.19.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] setvbuf: return failure if mode is invalid
  2019-03-12 20:31 [PATCH] setvbuf: return failure if mode is invalid A. Wilcox
@ 2019-03-13  0:32 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2019-03-13  0:32 UTC (permalink / raw)
  To: musl

On Tue, Mar 12, 2019 at 03:31:22PM -0500, A. Wilcox wrote:
> POSIX requires setvbuf to return non-zero if `mode` is not one of _IONBF,
> _IOLBF, or _IOFBF.
> ---
>  src/stdio/setvbuf.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c
> index 06ea296c..523dddc8 100644
> --- a/src/stdio/setvbuf.c
> +++ b/src/stdio/setvbuf.c
> @@ -12,13 +12,15 @@ int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size)
>  
>  	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;
> -- 
> 2.19.2

Thanks; will commit. FWIW this seems to be a C requirement not
specific to POSIX.

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-13  0:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12 20:31 [PATCH] setvbuf: return failure if mode is invalid A. Wilcox
2019-03-13  0:32 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).