diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 42 |
1 files changed, 27 insertions, 15 deletions
@@ -36,6 +36,10 @@ #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif +#ifndef ENFILE +#define ENFILE EMFILE +#endif + #ifndef atarist #define INVALID_HANDLE (-1) #else @@ -51,7 +55,7 @@ static int inrec P((IOBUF *iop)); static int iop_close P((IOBUF *iop)); struct redirect *redirect P((NODE *tree, int *errflg)); static void close_one P((void)); -static int close_redir P((struct redirect *rp)); +static int close_redir P((struct redirect *rp, int exitwarn)); #ifndef PIPES_SIMULATED static int wait_any P((int interesting)); #endif @@ -159,13 +163,13 @@ int skipping; void set_FNR() { - FNR = (int) FNR_node->var_value->numbr; + FNR = (long) FNR_node->var_value->numbr; } void set_NR() { - NR = (int) NR_node->var_value->numbr; + NR = (long) NR_node->var_value->numbr; } /* @@ -256,12 +260,12 @@ do_input() IOBUF *iop; extern int exiting; - if (setjmp(filebuf) != 0) { - } + (void) setjmp(filebuf); + while ((iop = nextfile(0)) != NULL) { if (inrec(iop) == 0) while (interpret(expression_value) && inrec(iop) == 0) - ; + continue; /* recover any space from C based alloca */ (void) alloca(0); @@ -409,7 +413,7 @@ int *errflg; } if (rp->fp == NULL && rp->iop == NULL) { /* too many files open -- close one and try again */ - if (errno == EMFILE) + if (errno == EMFILE || errno == ENFILE) close_one(); else { /* @@ -479,16 +483,18 @@ NODE *tree; if (rp == NULL) /* no match */ return tmp_number((AWKNUM) 0.0); fflush(stdout); /* synchronize regular output */ - tmp = tmp_number((AWKNUM)close_redir(rp)); + tmp = tmp_number((AWKNUM)close_redir(rp, 0)); rp = NULL; return tmp; } static int -close_redir(rp) +close_redir(rp, exitwarn) register struct redirect *rp; +int exitwarn; { int status = 0; + char *what; if (rp == NULL) return 0; @@ -507,14 +513,19 @@ register struct redirect *rp; rp->iop = NULL; } } + + what = (rp->flag & RED_PIPE) ? "pipe" : "file"; + + if (exitwarn) + warning("no explicit close of %s \"%s\" provided", + what, rp->value); + /* SVR4 awk checks and warns about status of close */ if (status) { char *s = strerror(errno); - warning("failure status (%d) on %s close of \"%s\" (%s).", - status, - (rp->flag & RED_PIPE) ? "pipe" : - "file", rp->value, s); + warning("failure status (%d) on %s close of \"%s\" (%s)", + status, what, rp->value, s); if (! do_unix) { /* set ERRNO too so that program can get at it */ @@ -572,7 +583,8 @@ close_io () for (rp = red_head; rp != NULL; rp = next) { next = rp->next; /* close_redir() will print a message if needed */ - if (close_redir(rp)) + /* if do_lint, warn about lack of explicit close */ + if (close_redir(rp, do_lint)) status++; rp = NULL; } @@ -794,7 +806,7 @@ const char *name, *mode; char tbuf[BUFSIZ], *cp; int i; #if defined(NGROUPS_MAX) && NGROUPS_MAX > 0 -#if defined(atarist) || defined(__svr4__) +#if defined(atarist) || defined(__svr4__) || defined(__osf__) gid_t groupset[NGROUPS_MAX]; #else int groupset[NGROUPS_MAX]; |