diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2016-11-18 06:10:12 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2016-11-18 06:10:12 +0200 |
commit | dc7bf0cfeb2ec3eb26f1767cfe8605199613c4d6 (patch) | |
tree | f2d6dcac2918d00cd31dd2dded7a776de7fa277e /io.c | |
parent | f0b405cceab16dadbb84b95a8d68f705bc20f70f (diff) | |
parent | c2448a50be949f5df2da4f7a1baf58358b297970 (diff) | |
download | egawk-dc7bf0cfeb2ec3eb26f1767cfe8605199613c4d6.tar.gz egawk-dc7bf0cfeb2ec3eb26f1767cfe8605199613c4d6.tar.bz2 egawk-dc7bf0cfeb2ec3eb26f1767cfe8605199613c4d6.zip |
Merge branch 'master' into feature/typed-regex-2
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 37 |
1 files changed, 26 insertions, 11 deletions
@@ -480,7 +480,6 @@ nextfile(IOBUF **curfile, bool skipping) if (arg == NULL || arg->stlen == 0) continue; arg = force_string(arg); - arg->stptr[arg->stlen] = '\0'; if (! do_traditional) { unref(ARGIND_node->var_value); ARGIND_node->var_value = make_number((AWKNUM) i); @@ -534,7 +533,7 @@ nextfile(IOBUF **curfile, bool skipping) unref(FILENAME_node->var_value); FILENAME_node->var_value = make_string("-", 1); - FILENAME_node->var_value->flags |= MAYBE_NUM; /* be pedantic */ + FILENAME_node->var_value->flags |= USER_INPUT; /* be pedantic */ fname = "-"; iop = iop_alloc(fileno(stdin), fname, 0); *curfile = iop_finish(iop); @@ -958,7 +957,7 @@ redirect_string(const char *str, size_t explen, bool not_string, #endif direction = "to/from"; if (! two_way_open(str, rp, extfd)) { - if (! failure_fatal || is_non_fatal_redirect(str)) { + if (! failure_fatal || is_non_fatal_redirect(str, explen)) { *errflg = errno; /* do not free rp, saving it for reuse (save_rp = rp) */ return NULL; @@ -1045,7 +1044,7 @@ redirect_string(const char *str, size_t explen, bool not_string, */ if (errflg != NULL) *errflg = errno; - if (failure_fatal && ! is_non_fatal_redirect(str) && + if (failure_fatal && ! is_non_fatal_redirect(str, explen) && (redirtype == redirect_output || redirtype == redirect_append)) { /* multiple messages make life easier for translators */ @@ -1126,10 +1125,21 @@ is_non_fatal_std(FILE *fp) /* is_non_fatal_redirect --- return true if redirected I/O should be nonfatal */ bool -is_non_fatal_redirect(const char *str) +is_non_fatal_redirect(const char *str, size_t len) { - return in_PROCINFO(nonfatal, NULL, NULL) != NULL - || in_PROCINFO(str, nonfatal, NULL) != NULL; + bool ret; + char save; + char *s = (char *) str; + + save = s[len]; + s[len] = '\0'; + + ret = in_PROCINFO(nonfatal, NULL, NULL) != NULL + || in_PROCINFO(s, nonfatal, NULL) != NULL; + + s[len] = save; + + return ret; } /* close_one --- temporarily close an open file to re-use the fd */ @@ -1183,7 +1193,11 @@ do_close(int nargs) if (nargs == 2) { /* 2nd arg if present: "to" or "from" for two-way pipe */ /* DO NOT use _() on the strings here! */ + char save; + tmp2 = POP_STRING(); + save = tmp2->stptr[tmp2->stlen]; + tmp2->stptr[tmp2->stlen] = '\0'; if (strcasecmp(tmp2->stptr, "to") == 0) how = CLOSE_TO; else if (strcasecmp(tmp2->stptr, "from") == 0) @@ -1192,6 +1206,7 @@ do_close(int nargs) DEREF(tmp2); fatal(_("close: second argument must be `to' or `from'")); } + tmp2->stptr[tmp2->stlen] = save; DEREF(tmp2); } @@ -1734,7 +1749,7 @@ devopen(const char *name, const char *mode) unsigned long retries = 0; static long msleep = 1000; bool hard_error = false; - bool non_fatal = is_non_fatal_redirect(name); + bool non_fatal = is_non_fatal_redirect(name, strlen(name)); cp = (char *) name; @@ -2620,7 +2635,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) } return make_number((AWKNUM) -1.0); } else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) { - if (is_non_fatal_redirect(redir_exp->stptr)) { + if (is_non_fatal_redirect(redir_exp->stptr, redir_exp->stlen)) { update_ERRNO_int(EBADF); return make_number((AWKNUM) -1.0); } @@ -2658,7 +2673,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) else { /* assignment to variable */ unref(*lhs); *lhs = make_string(s, cnt); - (*lhs)->flags |= MAYBE_NUM; + (*lhs)->flags |= USER_INPUT; } return make_number((AWKNUM) 1.0); @@ -2701,7 +2716,7 @@ do_getline(int into_variable, IOBUF *iop) lhs = POP_ADDRESS(); unref(*lhs); *lhs = make_string(s, cnt); - (*lhs)->flags |= MAYBE_NUM; + (*lhs)->flags |= USER_INPUT; } return make_number((AWKNUM) 1.0); } |