summaryrefslogtreecommitdiff
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-07-23 22:11:52 +0300
committerArnold D. Robbins <arnold@skeeve.com>2016-07-23 22:11:52 +0300
commitadb5491f2c9f49bf3d0e57f52c55bcaa4221e36e (patch)
tree4e76b81c1ec485cc10f52d47b699a894cf65a247 /builtin.c
parentb7a631b6fa5ed5577520eccb1608956bd40a74e0 (diff)
parentde23ab7bfbea6ee03ef7386c6c203a4b2b7b7116 (diff)
downloadgawk-adb5491f2c9f49bf3d0e57f52c55bcaa4221e36e.tar.gz
Merge branch 'master' into feature/nocopy
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/builtin.c b/builtin.c
index da3c252f..ab247a8b 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)
@@ -4048,3 +4038,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;
+}