diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-22T08·50+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-22T08·50+0000 |
commit | c4cb6ea2bc77f1f9239ce81ffc7a0fa6b540b1ab (patch) | |
tree | 73883262549f10206cc2a961dc7fb577f0ba1679 /src/libutil | |
parent | 88fb4f6e537ebea37fe0aaa4a2b044cf70d32178 (diff) |
* Refactoring.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 13 | ||||
-rw-r--r-- | src/libutil/util.hh | 5 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 2cfada35450a..d3446d38a6d8 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -491,3 +491,16 @@ Strings unpackStrings(const string & s) return strings; } + + +string statusToString(int status) +{ + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + if (WIFEXITED(status)) + return (format("failed with exit code %2%") % WEXITSTATUS(status)).str(); + else if (WIFSIGNALED(status)) + return (format("failed due to signal %2%") % WTERMSIG(status)).str(); + else + return "died abnormally"; + } else return "succeeded"; +} diff --git a/src/libutil/util.hh b/src/libutil/util.hh index e808f4e1b50b..21c6774b9d07 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -221,4 +221,9 @@ string packStrings(const Strings & strings); Strings unpackStrings(const string & s); +/* Convert the exit status of a child as returned by wait() into an + error string. */ +string statusToString(int status); + + #endif /* !__UTIL_H */ |