From owner-svn-src-all@FreeBSD.ORG Sun Jul 12 13:09:44 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 54D55106566C; Sun, 12 Jul 2009 13:09:44 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 42B6C8FC1E; Sun, 12 Jul 2009 13:09:44 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6CD9iCx085208; Sun, 12 Jul 2009 13:09:44 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6CD9iXj085206; Sun, 12 Jul 2009 13:09:44 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200907121309.n6CD9iXj085206@svn.freebsd.org> From: Ed Schouten Date: Sun, 12 Jul 2009 13:09:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195637 - head/lib/libc/stdio X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jul 2009 13:09:45 -0000 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;