shared/exit-status: add exit_status_from_string()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-07-29 15:54:53 +02:00
parent e1714f0250
commit f0d67dcddd
3 changed files with 33 additions and 0 deletions
+17
View File
@@ -6,7 +6,9 @@
#include "exit-status.h"
#include "macro.h"
#include "parse-util.h"
#include "set.h"
#include "string-util.h"
const ExitStatusMapping exit_status_mappings[256] = {
/* Exit status ranges:
@@ -117,6 +119,21 @@ const char* exit_status_class(int code) {
}
}
int exit_status_from_string(const char *s) {
uint8_t val;
int r;
for (size_t i = 0; i < ELEMENTSOF(exit_status_mappings); i++)
if (streq_ptr(s, exit_status_mappings[i].name))
return i;
r = safe_atou8(s, &val);
if (r < 0)
return r;
return val;
}
bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status) {
if (code == CLD_EXITED)
return status == 0 ||
+1
View File
@@ -89,6 +89,7 @@ typedef struct ExitStatusSet {
const char* exit_status_to_string(int code, ExitStatusClass class) _const_;
const char* exit_status_class(int code) _const_;
int exit_status_from_string(const char *s) _pure_;
typedef struct ExitStatusMapping {
const char *name;