From 771301de240465f7f4f1937661585e297309c3af Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 17 Nov 1996 00:22:54 +0000 Subject: [PATCH] Fix the C programmer's bug #1: EOF is of type `int', not `char'. Strong 2.2 candidate. Submitted by: wosch --- usr.bin/sed/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index dbea5049ab1f..bed4b182ada7 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -274,8 +274,7 @@ mf_fgets(sp, spflag) err(FATAL, "%s: %s", fname, strerror(errno)); } - if ((c = getc(f)) != EOF) { - (void)ungetc(c, f); + if (!feof(f)) { break; } (void)fclose(f); @@ -289,8 +288,6 @@ mf_fgets(sp, spflag) /* * 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. */ p = fgetln(f, &len); if (ferror(f)) @@ -299,7 +296,7 @@ mf_fgets(sp, spflag) linenum++; /* Advance to next non-empty file */ - while ((c = getc(f)) == EOF) { + while (feof(f)) { (void)fclose(f); files = files->next; if (files == NULL) { @@ -315,7 +312,6 @@ mf_fgets(sp, spflag) err(FATAL, "%s: %s", fname, strerror(errno)); } } - (void)ungetc(c, f); return (1); }