aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--awk.h2
-rw-r--r--interpret.h2
-rw-r--r--io.c10
4 files changed, 19 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 74bc3687..139bcd5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,16 @@
* main.c (usage): Put text for `-n' *after* text for `-m'.
Report from Robert P. J. Day <rpjday@crashcourse.ca>.
+ Fix problems with I/O errors reported by Assaf Gordon
+ <assafgordon@gmail.com>:
+
+ * io.c (inrec): Change type to bool to make calling easier. Add
+ check in non-EOF case for error, and if so, return false.
+ Update ERRNO in case there is an ENDFILE block.
+ * awk.h (inrec): Change type in declaration.
+ * interpret.h (r_interpret): Change call of inrec() to boolean
+ notation.
+
2014-07-10 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (check_for_bad): New routine to do the fatal message,
diff --git a/awk.h b/awk.h
index 65448400..a322a0b2 100644
--- a/awk.h
+++ b/awk.h
@@ -1531,7 +1531,7 @@ extern char *find_source(const char *src, struct stat *stb, int *errcode, int is
extern NODE *do_getline_redir(int intovar, enum redirval redirtype);
extern NODE *do_getline(int intovar, IOBUF *iop);
extern struct redirect *getredirect(const char *str, int len);
-extern int inrec(IOBUF *iop, int *errcode);
+extern bool inrec(IOBUF *iop, int *errcode);
extern int nextfile(IOBUF **curfile, bool skipping);
/* main.c */
extern int arg_assign(char *arg, bool initing);
diff --git a/interpret.h b/interpret.h
index 27f194ae..ff9ba768 100644
--- a/interpret.h
+++ b/interpret.h
@@ -1191,7 +1191,7 @@ match_re:
JUMPTO(ni);
}
- if (inrec(curfile, & errcode) != 0) {
+ if (! inrec(curfile, & errcode)) {
if (errcode > 0 && (do_traditional || ! pc->has_endfile))
fatal(_("error reading input file `%s': %s"),
curfile->public.name, strerror(errcode));
diff --git a/io.c b/io.c
index 57d4af22..45b5015f 100644
--- a/io.c
+++ b/io.c
@@ -574,12 +574,12 @@ set_NR()
/* inrec --- This reads in a record from the input file */
-int
+bool
inrec(IOBUF *iop, int *errcode)
{
char *begin;
int cnt;
- int retval = 0;
+ bool retval = true;
if (at_eof(iop) && no_data_left(iop))
cnt = EOF;
@@ -589,13 +589,17 @@ inrec(IOBUF *iop, int *errcode)
cnt = get_a_record(& begin, iop, errcode);
if (cnt == EOF) {
- retval = 1;
+ retval = false;
if (*errcode > 0)
update_ERRNO_int(*errcode);
} else {
INCREMENT_REC(NR);
INCREMENT_REC(FNR);
set_record(begin, cnt);
+ if (*errcode > 0) {
+ update_ERRNO_int(*errcode);
+ retval = false;
+ }
}
return retval;