From aca28ca9ac235250ba848c707522edddbac70c42 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 2 Aug 2003 19:53:52 +0000 Subject: [PATCH] (cut_fields): Don't read again after encountering EOF. E.g., `cut -f2' would do so. --- src/cut.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cut.c b/src/cut.c index bc7a26995a..e84d86131f 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; -- 2.47.2