summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-08-02 19:53:52 +0000
committerJim Meyering <jim@meyering.net>2003-08-02 19:53:52 +0000
commitaca28ca9ac235250ba848c707522edddbac70c42 (patch)
tree296e3afe3c6420a19fbfd75c06527fddef77ccbf
parent40944ce6ceb576174d80e65d41b1e0bd592535cf (diff)
downloadcoreutils-aca28ca9ac235250ba848c707522edddbac70c42.tar.xz
(cut_fields): Don't read again after encountering EOF.
E.g., `cut -f2' would do so.
-rw-r--r--src/cut.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/cut.c b/src/cut.c
index bc7a26995..e84d86131 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -563,15 +563,15 @@ cut_fields (FILE *stream)
unsigned int field_idx;
int found_any_selected_field;
int buffer_first_field;
- int empty_input;
found_any_selected_field = 0;
field_idx = 1;
c = getc (stream);
- empty_input = (c == EOF);
- if (c != EOF)
- ungetc (c, stream);
+ if (c == EOF)
+ return;
+
+ ungetc (c, stream);
/* To support the semantics of the -s flag, we may have to buffer
all of the first field to determine whether it is `delimited.'
@@ -667,7 +667,7 @@ cut_fields (FILE *stream)
else if (c == '\n' || c == EOF)
{
if (found_any_selected_field
- || (!empty_input && !(suppress_non_delimited && field_idx == 1)))
+ || !(suppress_non_delimited && field_idx == 1))
putchar ('\n');
if (c == EOF)
break;