Line | Branch | Exec | Source |
---|---|---|---|
1 | #ifndef UTIL_PROGNAME_H | ||
2 | #define UTIL_PROGNAME_H | ||
3 | |||
4 | #include "macros.h" | ||
5 | |||
6 | // Get the program name from argv[0] (as passed to main()), or fall back to a | ||
7 | // pre-defined string if it's missing | ||
8 | RETURNS_NONNULL | ||
9 | 7 | static inline const char *progname(int argc, char *argv[], const char *fallback) | |
10 | { | ||
11 | // Setting argv[0] properly is under the control of the parent process, | ||
12 | // so it's safest to make as few assumptions about it as possible | ||
13 |
6/6✓ Branch 0 (2→3) taken 4 times.
✓ Branch 1 (2→5) taken 3 times.
✓ Branch 2 (3→4) taken 3 times.
✓ Branch 3 (3→5) taken 1 times.
✓ Branch 4 (4→5) taken 1 times.
✓ Branch 5 (4→7) taken 2 times.
|
7 | if (likely(argc >= 1 && argv && argv[0] && argv[0][0])) { |
14 | return argv[0]; | ||
15 | } | ||
16 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 1 (5→7) taken 4 times.
|
5 | return fallback ? fallback : "_PROG_"; |
17 | } | ||
18 | |||
19 | #endif | ||
20 |