diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-20 15:42:57 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-20 18:40:02 +0100 |
commit | 294bf0c34a53caa25709b794bfeee6a00a2b6ecd (patch) | |
tree | a429db1ca92924ac73959a0ed9954161e22612dd /src/shared/main-func.h | |
parent | 0166c42868813d5d96b500277f6f819eef498b95 (diff) | |
download | systemd-294bf0c34a53caa25709b794bfeee6a00a2b6ecd.tar.gz |
Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
Diffstat (limited to 'src/shared/main-func.h')
-rw-r--r-- | src/shared/main-func.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/shared/main-func.h b/src/shared/main-func.h new file mode 100644 index 0000000000..24bf6c99bf --- /dev/null +++ b/src/shared/main-func.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +#include <stdlib.h> + +#include "pager.h" +#include "static-destruct.h" + +#define _DEFINE_MAIN_FUNCTION(impl, ret) \ + int main(int argc, char *argv[]) { \ + int r; \ + r = impl(argc, argv); \ + static_destruct(); \ + pager_close(); \ + return ret; \ + } + +/* Negative return values from impl are mapped to EXIT_FAILURE, and + * everything else means success! */ +#define DEFINE_MAIN_FUNCTION(impl) \ + _DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : EXIT_SUCCESS) + +/* Zero is mapped to EXIT_SUCCESS, negative values are mapped to EXIT_FAILURE, + * and postive values are propagated. + * Note: "true" means failure! */ +#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \ + _DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : r) |