From e796c010aaf623f0bb512202a85ecad8c30d317a Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 10 Apr 2004 14:43:30 +0000 Subject: [PATCH] Added a new module for formatting of process exit status messages. --- lib/exitstatus.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/exitstatus.c diff --git a/lib/exitstatus.c b/lib/exitstatus.c new file mode 100644 index 00000000..ed649f6d --- /dev/null +++ b/lib/exitstatus.c @@ -0,0 +1,36 @@ +/* + * Sherlock Library -- Formatting of Process Exit Status + * + * (c) 2004 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + +#include "lib/lib.h" + +#include +#include +#include + +int +format_exit_status(byte *msg, int stat) +{ + if (stat < 0) + sprintf(msg, "failed to fork (err=%d)", errno); + else if (WIFEXITED(stat) && WEXITSTATUS(stat) < 256) + { + if (WEXITSTATUS(stat)) + sprintf(msg, "died with exit code %d", WEXITSTATUS(stat)); + else + { + msg[0] = 0; + return 0; + } + } + else if (WIFSIGNALED(stat)) + sprintf(msg, "died on signal %d", WTERMSIG(stat)); + else + sprintf(msg, "died with status %x", stat); + return 1; +} -- 2.39.2