summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fwrite.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2009-07-12 18:45:21 +0000
committermillert <millert@openbsd.org>2009-07-12 18:45:21 +0000
commita6d7aecd3cf6f368005489220a4e67c63db49a69 (patch)
tree19eb6ea4770d2625593849a0a92517221e0f27e0 /lib/libc/stdio/fwrite.c
parentsync to 1.7.23: second step to get rid of enum mdoc_warn: (diff)
downloadwireguard-openbsd-a6d7aecd3cf6f368005489220a4e67c63db49a69.tar.xz
wireguard-openbsd-a6d7aecd3cf6f368005489220a4e67c63db49a69.zip
fwrite() should also return 0 if either size or nmemb are 0.
Adapted from FreeBSD. OK deraadt@
Diffstat (limited to 'lib/libc/stdio/fwrite.c')
-rw-r--r--lib/libc/stdio/fwrite.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c
index 8a508dcdba7..a60f9e0807a 100644
--- a/lib/libc/stdio/fwrite.c
+++ b/lib/libc/stdio/fwrite.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fwrite.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/* $OpenBSD: fwrite.c,v 1.6 2009/07/12 18:45:21 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -46,8 +46,14 @@ fwrite(const void *buf, size_t size, size_t count, FILE *fp)
struct __suio uio;
struct __siov iov;
+ /*
+ * ANSI and SUSv2 require a return value of 0 if size or count are 0.
+ */
+ if ((n = count * size) == 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;