summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sed
diff options
context:
space:
mode:
authorDan McDonald <danmcd@joyent.com>2020-09-22 10:39:49 -0400
committerDan McDonald <danmcd@joyent.com>2020-09-22 10:39:49 -0400
commit267e12a7d9bf6e5fcefb9cc00f46bfff0dc5226e (patch)
tree19a3941920d0039c35d53a5cbee189b5ca51995a /usr/src/cmd/sed
parent517abc5c668925e6092495bf332233c3599980d2 (diff)
parente9faba760cdf80d7dfa110fe0830917ab94668c2 (diff)
downloadillumos-joyent-vpc.tar.gz
Merge branch 'master' into vpcvpc
Diffstat (limited to 'usr/src/cmd/sed')
-rw-r--r--usr/src/cmd/sed/main.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/usr/src/cmd/sed/main.c b/usr/src/cmd/sed/main.c
index 2ada22edbb..b148f7293e 100644
--- a/usr/src/cmd/sed/main.c
+++ b/usr/src/cmd/sed/main.c
@@ -1,4 +1,5 @@
/*
+ * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
* Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.com>
* Copyright (c) 2011 Gary Mills
* Copyright 2010 Nexenta Systems, Inc. All rights reserved.
@@ -498,10 +499,30 @@ lastline(void)
{
int ch;
- if (files->next != NULL && (inplace == NULL || ispan))
- return (0);
- if ((ch = getc(infile)) == EOF)
+ if (feof(infile) != 0 || (ch = getc(infile)) == EOF) {
+ struct s_flist *f;
+
+ /*
+ * Reached the end of the current input file.
+ * If there are no more that contain data, then this is the
+ * last line.
+ */
+ if (inplace != NULL && ispan == 0)
+ return (1);
+
+ for (f = files->next; f != NULL; f = f->next) {
+ struct stat st;
+
+ if (stat(f->fname, &st) == -1) {
+ /* Treat an error here as an empty file */
+ continue;
+ }
+ if (st.st_size > 0)
+ return (0);
+ }
return (1);
+ }
+
(void) ungetc(ch, infile);
return (0);
}