From 140a4a886edc231f1c5f02c6cd4c82effe58139e Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 23 Jul 2016 21:59:40 +0300 Subject: Fix do_print for use with strnums. --- builtin.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 67424663..0163b81c 100644 --- a/builtin.c +++ b/builtin.c @@ -2179,12 +2179,8 @@ do_print(int nargs, int redirtype) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(tmp)); } - if ((tmp->flags & (NUMBER|STRING)) == NUMBER) { - if (OFMTidx == CONVFMTidx) - args_array[i] = force_string(tmp); - else - args_array[i] = format_val(OFMT, OFMTidx, tmp); - } + if ((tmp->flags & STRCUR) == 0 || (tmp->stfmt != -1 && tmp->stfmt != OFMTidx)) + args_array[i] = format_val(OFMT, OFMTidx, tmp); } if (redir_exp != NULL) { -- cgit v1.2.3 From de23ab7bfbea6ee03ef7386c6c203a4b2b7b7116 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 23 Jul 2016 22:10:25 +0300 Subject: Make return status of close on a pipe like system. --- builtin.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 77cf3fc5..87f7fb23 100644 --- a/builtin.c +++ b/builtin.c @@ -2124,22 +2124,12 @@ do_system(int nargs) ; /* leave it alone, full 16 bits */ else if (do_traditional) #ifdef __MINGW32__ - ret = (((unsigned)status) & ~0xC0000000); + ret = (((unsigned)status) & ~0xC0000000); #else ret = (status / 256.0); #endif - else if (WIFEXITED(status)) - ret = WEXITSTATUS(status); /* normal exit */ - else if (WIFSIGNALED(status)) { - bool coredumped = false; -#ifdef WCOREDUMP - coredumped = WCOREDUMP(status); -#endif - /* use 256 since exit values are 8 bits */ - ret = WTERMSIG(status) + - (coredumped ? 512 : 256); - } else - ret = 0; /* shouldn't get here */ + else + ret = sanitize_exit_status(status); } if ((BINMODE & BINMODE_INPUT) != 0) @@ -4054,3 +4044,24 @@ mbc_char_count(const char *ptr, size_t numbytes) return sum; } + +/* sanitize_exit_status --- convert a 16 bit Unix exit status into something reasonable */ + +int sanitize_exit_status(int status) +{ + int ret = 0; + + if (WIFEXITED(status)) + ret = WEXITSTATUS(status); /* normal exit */ + else if (WIFSIGNALED(status)) { + bool coredumped = false; +#ifdef WCOREDUMP + coredumped = WCOREDUMP(status); +#endif + /* use 256 since exit values are 8 bits */ + ret = WTERMSIG(status) + (coredumped ? 512 : 256); + } else + ret = 0; /* shouldn't get here */ + + return ret; +} -- cgit v1.2.3