summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fwrite.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-07-12 13:09:43 +0000
committered <ed@FreeBSD.org>2009-07-12 13:09:43 +0000
commit32d59587cd275dd8b0e8db80ddc997a52e0771fa (patch)
tree741c7d82471fa232d1d4175dea3bee1977667a58 /lib/libc/stdio/fwrite.c
parentd144bd09876b8dea20687370a97bed68d1e1dd5e (diff)
downloadFreeBSD-src-32d59587cd275dd8b0e8db80ddc997a52e0771fa.zip
FreeBSD-src-32d59587cd275dd8b0e8db80ddc997a52e0771fa.tar.gz
Fix fwrite() to return 0 when size or nmemb are zero.
Right now nmemb is returned when size is 0. In newer versions of the standards, it is explicitly required that fwrite() should return 0. Submitted by: Christoph Mallon Approved by: re (kib)
Diffstat (limited to 'lib/libc/stdio/fwrite.c')
-rw-r--r--lib/libc/stdio/fwrite.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c
index 999d595..cf52e42 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;
OpenPOWER on IntegriCloud