Date: Sun, 12 Jul 2009 13:09:44 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r195637 - head/lib/libc/stdio Message-ID: <200907121309.n6CD9iXj085206@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Sun Jul 12 13:09:43 2009 New Revision: 195637 URL: http://svn.freebsd.org/changeset/base/195637 Log: 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) Modified: head/lib/libc/stdio/fread.c head/lib/libc/stdio/fwrite.c Modified: head/lib/libc/stdio/fread.c ============================================================================== --- head/lib/libc/stdio/fread.c Sun Jul 12 12:50:43 2009 (r195636) +++ head/lib/libc/stdio/fread.c Sun Jul 12 13:09:43 2009 (r195637) @@ -67,9 +67,7 @@ __fread(void * __restrict buf, size_t si 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); Modified: head/lib/libc/stdio/fwrite.c ============================================================================== --- head/lib/libc/stdio/fwrite.c Sun Jul 12 12:50:43 2009 (r195636) +++ head/lib/libc/stdio/fwrite.c Sun Jul 12 13:09:43 2009 (r195637) @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907121309.n6CD9iXj085206>