dte test coverage


Directory: ./
File: src/util/exitcode.h
Date: 2025-06-04 06:50:24
Exec Total Coverage
Lines: 3 6 50.0%
Functions: 1 2 50.0%
Branches: 1 2 50.0%

Line Branch Exec Source
1 #ifndef UTIL_EXITCODE_H
2 #define UTIL_EXITCODE_H
3
4 #include <stdio.h>
5 #include <unistd.h>
6 #include "macros.h"
7 #include "xreadwrite.h"
8
9 // Semantic exit codes, as defined by BSD sysexits(3)
10 enum {
11 EC_OK = 0, // Exited normally (EX_OK)
12 EC_USAGE_ERROR = 64, // Command line usage error (EX_USAGE)
13 EC_DATA_ERROR = 65, // Input data error (EX_DATAERR)
14 EC_OS_ERROR = 71, // Operating system error (EX_OSERR)
15 EC_IO_ERROR = 74, // Input/output error (EX_IOERR)
16 EC_CONFIG_ERROR = 78, // Configuration error (EX_CONFIG)
17 };
18
19 // This exists purely for "self-documentation" purposes. Functions
20 // returning this type should only return one of the above values.
21 typedef int ExitCode;
22
23 static inline ExitCode ec_error(const char *prefix, ExitCode ec)
24 {
25 perror(prefix);
26 return ec;
27 }
28
29 3 static inline ExitCode ec_write_stdout(const char *str, size_t len)
30 {
31 3 ssize_t r = xwrite_all(STDOUT_FILENO, str, len);
32
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 3 times.
3 return likely(r >= 0) ? EC_OK : ec_error("write", EC_IO_ERROR);
33 }
34
35 ExitCode ec_usage_error(const char *restrict fmt, ...) PRINTF(1) NONNULL_ARGS;
36 ExitCode ec_printf_ok(const char *restrict fmt, ...) PRINTF(1) NONNULL_ARGS;
37
38 #endif
39