From owner-svn-src-head@FreeBSD.ORG Wed Jun 26 04:14:20 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 0AB07D14; Wed, 26 Jun 2013 04:14:20 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id D7BDC1C22; Wed, 26 Jun 2013 04:14:19 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5Q4EJT8078671; Wed, 26 Jun 2013 04:14:19 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5Q4EJb9078670; Wed, 26 Jun 2013 04:14:19 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201306260414.r5Q4EJb9078670@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Wed, 26 Jun 2013 04:14:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252231 - 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.14 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, 26 Jun 2013 04:14:20 -0000 Author: pfg Date: Wed Jun 26 04:14:19 2013 New Revision: 252231 URL: http://svnweb.freebsd.org/changeset/base/252231 Log: sed: use getline() instead of fgetln(). In BSD, fgetln() available in libc but in Illumos the Solaris port had to include it internally. It also seems to have caused problems [1]. Aid portability by using getline() instead. Reference: https://www.illumos.org/issues/3820 [1] Submitted by: Johann 'Myrkraverk' Oskarsson Reviewed by: dds MFC after: 2 weeks Modified: head/usr.bin/sed/main.c Modified: head/usr.bin/sed/main.c ============================================================================== --- head/usr.bin/sed/main.c Wed Jun 26 04:00:52 2013 (r252230) +++ head/usr.bin/sed/main.c Wed Jun 26 04:14:19 2013 (r252231) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson. * Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -57,6 +58,7 @@ static const char sccsid[] = "@(#)main.c #include #include #include +#define _WITH_GETLINE #include #include #include @@ -307,8 +309,9 @@ int mf_fgets(SPACE *sp, enum e_spflag spflag) { struct stat sb; - size_t len; - char *p; + ssize_t len; + static char *p = NULL; + static size_t plen = 0; int c; static int firstfile; @@ -424,13 +427,13 @@ mf_fgets(SPACE *sp, enum e_spflag spflag * We are here only when infile is open and we still have something * to read from it. * - * Use fgetln so that we can handle essentially infinite input data. - * Can't use the pointer into the stdio buffer as the process space - * because the ungetc() can cause it to move. + * Use getline() so that we can handle essentially infinite input + * data. The p and plen are static so each invocation gives + * getline() the same buffer which is expanded as needed. */ - p = fgetln(infile, &len); - if (ferror(infile)) - errx(1, "%s: %s", fname, strerror(errno ? errno : EIO)); + len = getline(&p, &plen, infile); + if (len == -1) + err(1, "%s", fname); if (len != 0 && p[len - 1] == '\n') len--; cspace(sp, p, len, spflag);