Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Jun 2014 18:48:18 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Pedro Giffuni <pfg@freebsd.org>
Cc:        Konstantin Belousov <kostikbel@gmail.com>, svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r267692 - head/usr.bin/sed
Message-ID:  <20140621183648.M5055@besplex.bde.org>
In-Reply-To: <BE9F2DB0-5C97-41DA-853E-F01BA39D3319@freebsd.org>
References:  <201406202141.s5KLfU2J047433@svn.freebsd.org> <20140621054744.GN3991@kib.kiev.ua> <BE9F2DB0-5C97-41DA-853E-F01BA39D3319@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 21 Jun 2014, Pedro Giffuni wrote:

> Il giorno 21/giu/2014, alle ore 00:47, Konstantin Belousov <kostikbel@gma=
il.com> 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-all@FreeBSD.ORG  Sat Jun 21 14:07:35 2014
Return-Path: <owner-svn-src-all@FreeBSD.ORG>
Delivered-To: svn-src-all@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" <pfg@FreeBSD.org>
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-all@freebsd.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: "SVN commit messages for the entire src tree \(except for &quot;
 user&quot; and &quot; projects&quot; \)" <svn-src-all.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all/>;
List-Post: <mailto:svn-src-all@freebsd.org>
List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-all>,
 <mailto:svn-src-all-request@freebsd.org?subject=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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140621183648.M5055>