From 1b629e865eaaad178e515a7bf0fbf73b847cc6d6 Mon Sep 17 00:00:00 2001 From: "Jordan K. Hubbard" Date: Tue, 2 Mar 2004 19:43:51 +0000 Subject: [PATCH] If handed a file pointer we can't write to, set errno properly to EBADF in order to get SUSv2 conformant behavior in higher level calls like fputs() and puts(). Reviewed by: bde --- lib/libc/stdio/fvwrite.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 192edf81c90..cacad7f96d6 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -67,8 +68,10 @@ __sfvwrite(fp, uio) if ((len = uio->uio_resid) == 0) return (0); /* make sure we can write */ - if (cantwrite(fp)) + if (cantwrite(fp)) { + errno = EBADF; return (EOF); + } #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))