From owner-svn-src-head@FreeBSD.ORG Sat Jun 21 08:48:31 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 57455795; Sat, 21 Jun 2014 08:48:31 +0000 (UTC) Received: from mail108.syd.optusnet.com.au (mail108.syd.optusnet.com.au [211.29.132.59]) by mx1.freebsd.org (Postfix) with ESMTP id 1763F2E90; Sat, 21 Jun 2014 08:48:30 +0000 (UTC) Received: from c122-106-147-133.carlnfd1.nsw.optusnet.com.au (c122-106-147-133.carlnfd1.nsw.optusnet.com.au [122.106.147.133]) by mail108.syd.optusnet.com.au (Postfix) with ESMTPS id E9B3E1A4618; Sat, 21 Jun 2014 18:48:21 +1000 (EST) Date: Sat, 21 Jun 2014 18:48:18 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Pedro Giffuni Subject: Re: svn commit: r267692 - head/usr.bin/sed In-Reply-To: Message-ID: <20140621183648.M5055@besplex.bde.org> References: <201406202141.s5KLfU2J047433@svn.freebsd.org> <20140621054744.GN3991@kib.kiev.ua> MIME-Version: 1.0 X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=eojmkOZX c=1 sm=1 tr=0 a=7NqvjVvQucbO2RlWB8PEog==:117 a=PO7r1zJSAAAA:8 a=PIuYOccYB40A:10 a=JzwRw_2MAAAA:8 a=nlC_4_pT8q9DhB4Ho9EA:9 a=cz2ZRIgtxKwA:10 a=wJWlkF7cXJYA:10 a=pGLkceISAAAA:8 a=ieaRINkLfCv41KScPV0A:9 a=45ClL6m2LaAA:10 a=MSl-tDqOz04A:10 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE X-Content-Filtered-By: Mailman/MimeDel 2.1.18 Cc: Konstantin Belousov , svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 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: Sat, 21 Jun 2014 08:48:31 -0000 On Sat, 21 Jun 2014, Pedro Giffuni wrote: > Il giorno 21/giu/2014, alle ore 00:47, Konstantin Belousov ha scritto: > >> On Fri, Jun 20, 2014 at 09:41:30PM +0000, Pedro F. Giffuni wrote: >>> Modified: head/usr.bin/sed/main.c >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D >>> --- head/usr.bin/sed/main.c=09Fri Jun 20 21:35:39 2014=09(r267691) >>> +++ head/usr.bin/sed/main.c=09Fri Jun 20 21:41:30 2014=09(r267692) >>> ... >>> @@ -168,6 +168,16 @@ main(int argc, char *argv[]) >>> =09=09case 'n': >>> =09=09=09nflag =3D 1; >>> =09=09=09break; >>> +=09=09case 'u': >>> +#ifdef _IONBF >>> +=09=09=09c =3D setvbuf(stdout, NULL, _IONBF, 0); >>> +#else >>> +=09=09=09c =3D -1; >>> +=09=09=09errno =3D EOPNOTSUPP; >>> +#endif >>> +=09=09=09if (c) >> >> Why doing it that way ? IMO the conditional is useless and even wrong. >> FreeBSD provides the _IONBF, _IONBF is required by C99. >> >> If some other system lacks _IONBF, it should get compiler error instead >> of silently accepting non-working code. > > I was just trying to keep the code somewhat in sync with NetBSD: as of la= tely their emphasis is portability and for them it=92s important to be buil= d all their system in weird platforms. > > I agree it=92s ugly though, so unless someone thinks we should care I wil= l clean it up :). The ifdef is nonsense. _IONBUF and setvbuf() are far more portable than EOPNOTSUPP, since they are in C90 while EOPNOTSUPP wasn't even in POSIX until 2001. (POSIX spelled it ENOTSUP, but other OSes spelled it EOPNOTSUP= P, so now everyone except C has both.) Before C90, setvbuf() was unportable and there were ifdef messes to use it if available, else use setbuf(), but setbuf() can't do much. The 'c' variable is abused. Bruce From owner-svn-src-head@FreeBSD.ORG Sat Jun 21 14:07:35 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 104193AA; Sat, 21 Jun 2014 14:07:35 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EC97C25B6; Sat, 21 Jun 2014 14:07:34 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5LE7Y6i002184; Sat, 21 Jun 2014 14:07:34 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5LE7Yqv002183; Sat, 21 Jun 2014 14:07:34 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201406211407.s5LE7Yqv002183@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Sat, 21 Jun 2014 14:07:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267703 - head/usr.bin/sed X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 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: Sat, 21 Jun 2014 14:07:35 -0000 Author: pfg Date: Sat Jun 21 14:07:33 2014 New Revision: 267703 URL: http://svnweb.freebsd.org/changeset/base/267703 Log: Drop ifdef nonsense: just use setvbuf(3). Pointed out by: kib, bde Modified: head/usr.bin/sed/main.c Modified: head/usr.bin/sed/main.c ============================================================================== --- head/usr.bin/sed/main.c Sat Jun 21 02:24:35 2014 (r267702) +++ head/usr.bin/sed/main.c Sat Jun 21 14:07:33 2014 (r267703) @@ -162,20 +162,14 @@ main(int argc, char *argv[]) ispan = 0; /* don't span across input files */ break; case 'l': - if(setlinebuf(stdout) != 0) - warnx("setlinebuf() failed"); + if(setvbuf(stdout, NULL, _IOLBF, 0) != 0) + warnx("setting line buffered output failed"); break; case 'n': nflag = 1; break; case 'u': -#ifdef _IONBF - c = setvbuf(stdout, NULL, _IONBF, 0); -#else - c = -1; - errno = EOPNOTSUPP; -#endif - if (c) + if(setvbuf(stdout, NULL, _IONBF, 0) != 0) warnx("setting unbuffered output failed"); break; default: