diff options
author | Denys Vlasenko | 2023-05-28 17:25:56 +0200 |
---|---|---|
committer | Denys Vlasenko | 2023-05-28 17:25:56 +0200 |
commit | b76b420b5da1aadad823faf12327b610614f5951 (patch) | |
tree | 38754bece4f1ded6b050047905e688abbe829b37 | |
parent | 9790eb73c8b7ed1a1015f58e1fe85de0508c0526 (diff) | |
download | busybox-b76b420b5da1aadad823faf12327b610614f5951.zip busybox-b76b420b5da1aadad823faf12327b610614f5951.tar.gz |
awk: fix closing of non-opened file
function old new delta
setvar_ERRNO - 53 +53
.rodata 105252 105246 -6
awk_getline 639 620 -19
evaluate 3402 3377 -25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 53/-50) Total: 3 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/editors/awk.c b/editors/awk.c index 77e0b0a..83a08aa 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -1006,6 +1006,11 @@ static var *setvar_i(var *v, double value) return v; } +static void setvar_ERRNO(void) +{ + setvar_i(intvar[ERRNO], errno); +} + static const char *getvar_s(var *v) { /* if v is numeric and has no cached string, convert it to string */ @@ -2305,7 +2310,7 @@ static int awk_getline(rstream *rsm, var *v) if (p < pp) { p = 0; r = 0; - setvar_i(intvar[ERRNO], errno); + setvar_ERRNO(); } b[p] = '\0'; } while (p > pp); @@ -3249,7 +3254,7 @@ static var *evaluate(node *op, var *res) } if (!rsm->F) { - setvar_i(intvar[ERRNO], errno); + setvar_ERRNO(); setvar_i(res, -1); break; } @@ -3388,16 +3393,18 @@ static var *evaluate(node *op, var *res) */ if (rsm->F) err = rsm->is_pipe ? pclose(rsm->F) : fclose(rsm->F); -//TODO: fix this case: -// $ awk 'BEGIN { print close(""); print ERRNO }' -// -1 -// close of redirection that was never opened -// (we print 0, 0) free(rsm->buffer); hash_remove(fdhash, L.s); + } else { + err = -1; + /* gawk 'BEGIN { print close(""); print ERRNO }' + * -1 + * close of redirection that was never opened + */ + errno = ENOENT; } if (err) - setvar_i(intvar[ERRNO], errno); + setvar_ERRNO(); R_d = (double)err; break; } |