summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sed/main.c
diff options
context:
space:
mode:
authorKeith M Wesolowski <wesolows@foobazco.org>2013-06-25 18:55:57 +0000
committerKeith M Wesolowski <wesolows@foobazco.org>2013-06-25 18:58:03 +0000
commit1b8e2ab22100cf95c6c6ec115edcb7fbd2884bcf (patch)
tree5948ba2b7d57a00821e6ea8bd7e62c0f3040b81a /usr/src/cmd/sed/main.c
parentb061d3188d42c259e153cd6839fbeaacc4ccbfce (diff)
parent13c8743e4d3cc6d9653687512c0d48d2b653513d (diff)
downloadillumos-joyent-1b8e2ab22100cf95c6c6ec115edcb7fbd2884bcf.tar.gz
[illumos-gate merge]
commit 13c8743e4d3cc6d9653687512c0d48d2b653513d 3814 Support for SATA III Reviewed by: Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Reviewed by: Garrett D'Amore <garrett@damore.org> commit 257c04ecb24858f6d68020a41589306f554ea434 3815 AHCI: Support for Marvell 88SE9128 Reviewed by: Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Reviewed by: Garrett D'Amore <garrett@damore.org> commit 9384cec630155c229c70dfb8a445c6ccf433045a 3820 /usr/bin/sed doesn't handle binary files. Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> Reviewed by: Richard Lowe <richlowe@richlowe.net> Reviewed by: Marcel Telka <marcel@telka.sk> commit deeb0f36019670ade13450cb986b946c2e4002e6 3837 Get rid of custom getln() implementation from whois.c Reviewed by: Marcel Telka <marcel@telka.sk> Reviewed by: Yuri Pankov <yuri@xvoid.org> commit 588ef7d7682af16db66cd51d457078fea0519e47 3036 Update hwdata to current upstream data commit 0f24ff92c543e3909da566a91add6a92bcad02ed 3788 /etc/bootrc is defunct and should be removed Conflict: usr/src/cmd/hwdata/pci.ids Conflict: usr/src/cmd/prtconf/prtconf.c Manifest: usr/src/pkg/manifests/driver-network-platform.mf
Diffstat (limited to 'usr/src/cmd/sed/main.c')
-rw-r--r--usr/src/cmd/sed/main.c57
1 files changed, 10 insertions, 47 deletions
diff --git a/usr/src/cmd/sed/main.c b/usr/src/cmd/sed/main.c
index 59a6da8e22..dc3ef02619 100644
--- a/usr/src/cmd/sed/main.c
+++ b/usr/src/cmd/sed/main.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.com>
* Copyright (c) 2011 Gary Mills
* Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 1992 Diomidis Spinellis.
@@ -108,7 +109,6 @@ ulong_t linenum;
static void add_compunit(enum e_cut, char *);
static void add_file(char *);
static void usage(void);
-static char *getln(FILE *, size_t *);
int
@@ -305,8 +305,9 @@ int
mf_fgets(SPACE *sp, enum e_spflag spflag)
{
struct stat sb, nsb;
- size_t len;
- char *p;
+ ssize_t len;
+ static char *p = NULL;
+ static size_t plen = 0;
int c;
static int firstfile;
@@ -441,13 +442,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 = getln(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);
@@ -502,41 +503,3 @@ lastline(void)
(void) ungetc(ch, infile);
return (0);
}
-
-char *
-getln(FILE *in, size_t *lenp)
-{
- static char *buffer = NULL;
- static size_t sz = 0;
-
- size_t len = 0;
-
- for (;;) {
- if (sz <= (len + 1)) {
- char *nb;
- if ((nb = realloc(buffer, sz + LINE_MAX)) == NULL) {
- err(1, "realloc");
- }
- buffer = nb;
- sz += LINE_MAX;
- }
-
- buffer[len] = 0;
-
- if (fgets(buffer + len, sz - len, in) == NULL) {
- /* END OF FILE */
- *lenp = len;
- break;
- }
-
- len += strlen(buffer + len);
-
- if (buffer[len - 1] == '\n') {
- /* got the new line */
- *lenp = len;
- break;
- }
- }
-
- return (buffer);
-}