diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-05-13 18:24:57 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-05-13 18:24:57 +0200 |
commit | 633f43164d8245e388a71ab499aff4b3b2b79ceb (patch) | |
tree | ea2c7d11dc5219002e0492a7e60a619d2865f9cd /src/common | |
parent | 097fc9bdb386705a63a8021d5467266a70e22a6e (diff) | |
download | blogc-633f43164d8245e388a71ab499aff4b3b2b79ceb.tar.gz blogc-633f43164d8245e388a71ab499aff4b3b2b79ceb.tar.bz2 blogc-633f43164d8245e388a71ab499aff4b3b2b79ceb.zip |
make: git-receiver: fixed conversion from wait status to status code
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 39 | ||||
-rw-r--r-- | src/common/compat.h | 14 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c new file mode 100644 index 0000000..f7394c8 --- /dev/null +++ b/src/common/compat.c @@ -0,0 +1,39 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif /* HAVE_SYS_WAIT_H */ + +#include <signal.h> +#include "compat.h" + + +int +bc_compat_status_code(int waitstatus) +{ + int rv = waitstatus; +#if defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSIGNALED) && defined(WTERMSIG) + if (WIFEXITED(waitstatus)) { + rv = WEXITSTATUS(waitstatus); + } + else if (WIFSIGNALED(waitstatus)) { + rv = WTERMSIG(waitstatus); + rv += 128; + } +#elif defined(WIN32) || defined(_WIN32) + if (waitstatus == 3) { + rv = SIGTERM + 128; // can't get signal on windows. + } +#endif + return rv; +} diff --git a/src/common/compat.h b/src/common/compat.h new file mode 100644 index 0000000..021dc6e --- /dev/null +++ b/src/common/compat.h @@ -0,0 +1,14 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2014-2017 Rafael G. Martins <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifndef _COMPAT_H +#define _COMPAT_H + +int bc_compat_status_code(int waitstatus); + +#endif /* _COMPAT_H */ |