Date: Wed, 10 Jul 2013 21:05:03 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r253171 - stable/9/usr.bin/sed Message-ID: <201307102105.r6AL535O084689@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Wed Jul 10 21:05:03 2013 New Revision: 253171 URL: http://svnweb.freebsd.org/changeset/base/253171 Log: MFC r252231: 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. Modified: stable/9/usr.bin/sed/main.c Directory Properties: stable/9/usr.bin/sed/ (props changed) Modified: stable/9/usr.bin/sed/main.c ============================================================================== --- stable/9/usr.bin/sed/main.c Wed Jul 10 20:56:04 2013 (r253170) +++ stable/9/usr.bin/sed/main.c Wed Jul 10 21:05:03 2013 (r253171) @@ -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 <locale.h> #include <regex.h> #include <stddef.h> +#define _WITH_GETLINE #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307102105.r6AL535O084689>