diff options
author | Ed Schouten <ed@FreeBSD.org> | 2009-07-12 13:09:43 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2009-07-12 13:09:43 +0000 |
commit | 77822acff7bf72c4a8e4020fb9256372f851c65e (patch) | |
tree | 741c7d82471fa232d1d4175dea3bee1977667a58 | |
parent | 5861f9665471e98e544f6fa3ce73c4912229ff82 (diff) |
Notes
-rw-r--r-- | lib/libc/stdio/fread.c | 4 | ||||
-rw-r--r-- | lib/libc/stdio/fwrite.c | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index 851713be461f..6253856b9e33 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -67,9 +67,7 @@ __fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) size_t total; /* - * The ANSI standard requires a return value of 0 for a count - * or a size of 0. Peculiarily, it imposes no such requirements - * on fwrite; it only requires fread to be broken. + * ANSI and SUSv2 require a return value of 0 if size or count are 0. */ if ((resid = count * size) == 0) return (0); diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index 999d5958193d..cf52e42f615f 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -57,8 +57,15 @@ fwrite(buf, size, count, fp) struct __suio uio; struct __siov iov; + /* + * ANSI and SUSv2 require a return value of 0 if size or count are 0. + */ + n = count * size; + if (n == 0) + return (0); + iov.iov_base = (void *)buf; - uio.uio_resid = iov.iov_len = n = count * size; + uio.uio_resid = iov.iov_len = n; uio.uio_iov = &iov; uio.uio_iovcnt = 1; |