Created
January 17, 2014 09:51
-
-
Save edenhill/8470811 to your computer and use it in GitHub Desktop.
WIFEXIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a human readable process exit reason based on the exit code. | |
*/ | |
const char *exec_exitstatus (int status) { | |
static __thread char ret[128]; | |
if (WIFEXITED(status)) { | |
if (WEXITSTATUS(status) == 127) | |
snprintf(ret, sizeof(ret), | |
"could not execute command"); | |
else | |
snprintf(ret, sizeof(ret), "exited with status %i", | |
WEXITSTATUS(status)); | |
} else if (WIFSIGNALED(status)) { | |
#ifdef WCOREDUMP | |
if (WCOREDUMP(status)) | |
snprintf(ret, sizeof(ret), "core dumped"); | |
else | |
#endif | |
snprintf(ret, sizeof(ret), "terminated by signal %i", | |
WTERMSIG(status)); | |
} else | |
snprintf(ret, sizeof(ret), "exited with code %i", status); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment