From owner-svn-src-head@freebsd.org Wed May 3 06:56:58 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4120ED5B623; Wed, 3 May 2017 06:56:58 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id 0C302AAD; Wed, 3 May 2017 06:56:57 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from besplex.bde.org (c122-106-153-191.carlnfd1.nsw.optusnet.com.au [122.106.153.191]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id 830FC10725B; Wed, 3 May 2017 16:55:33 +1000 (AEST) Date: Wed, 3 May 2017 16:55:33 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Jilles Tjoelker cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r317709 - head/usr.bin/csplit In-Reply-To: <201705022156.v42LuKbp088899@repo.freebsd.org> Message-ID: <20170503162918.U1062@besplex.bde.org> References: <201705022156.v42LuKbp088899@repo.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=VbSHBBh9 c=1 sm=1 tr=0 a=Tj3pCpwHnMupdyZSltBt7Q==:117 a=Tj3pCpwHnMupdyZSltBt7Q==:17 a=kj9zAlcOel0A:10 a=SdYdQEDqucMlUsDrDG4A:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 May 2017 06:56:58 -0000 On Tue, 2 May 2017, Jilles Tjoelker wrote: > Log: > csplit: Fix check of fputs() return value, making csplit work again. > > As of r295638, fputs() returns the number of bytes written (if not more than > INT_MAX). This broke csplit completely, since csplit assumed only success > only for the return value 0. > > PR: 213510 > Submitted by: J.R. Oldroyd > MFC after: 1 week > Relnotes: yes > > Modified: > head/usr.bin/csplit/csplit.c > > Modified: head/usr.bin/csplit/csplit.c > ============================================================================== > --- head/usr.bin/csplit/csplit.c Tue May 2 21:33:27 2017 (r317708) > +++ head/usr.bin/csplit/csplit.c Tue May 2 21:56:20 2017 (r317709) > @@ -195,7 +195,7 @@ main(int argc, char *argv[]) > /* Copy the rest into a new file. */ > if (!feof(infile)) { > ofp = newfile(); > - while ((p = get_line()) != NULL && fputs(p, ofp) == 0) > + while ((p = get_line()) != NULL && fputs(p, ofp) != EOF) > ; > if (!sflag) > printf("%jd\n", (intmax_t)ftello(ofp)); I don't like checking for the specific value EOF instead of any negative value, though the EOF is Standard and I like checking for specific -1 for sysctls. stdio is not very consistent, and this bug is due to old versions of FreeBSD documenting and returning the specific value 0 on non-error, which was also Standard. Grepping for fputs in /usr/src shows too many instances to check (mostly without any error handling). The simplest filter 'if (fputs' found the dependency on the old FreeBSD behaviour in csplit and 2 other places: contrib/mdocml/main.c: if (fputs(cp, stdout)) { contrib/mdocml/main.c- fclose(stream); contrib/libreadline/examples/rlcat.c: if (fputs (x, stdout) != 0) contrib/libreadline/examples/rlcat.c- return 1; More complicated filters like 'if ([^(]]*[^a-z_]fputs' failed to find any problems since I messed up the regexp. mdocml is undocumented in its on man page, since that man page is a link to mandoc(1) nad doesn't contain the word mdocml. Bruce