diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 00:30:44 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 00:30:44 -0600 |
| commit | 5f92e02ff71be19067a422d324beb610cacd084d (patch) | |
| tree | 1af510b0e4b9e3de95b18f476a6ebff2f109c488 /src/trap.c | |
| parent | 7a7320b6a0d7dd6864b708b7e74fb5032a5bdf8e (diff) | |
| download | zash-chore/c23-nullptr-constexpr.tar.gz | |
C23: nullptr for null pointers, constexpr for typed constantschore/c23-nullptr-constexpr
nullptr in every place a null pointer constant was meant; NULL is gone
from src/.
constexpr where it improves on #define without costing anything: the
IGGCSI00 work-area offsets and sizes, and the scalar sizes MVS_DSN_MAX,
CSI_FIELD_LEN, CSI_WORK_MIN, PDS_DIRBLK, CSI_WORK, CSI_MAX_CALLS. A
constexpr in C is a constant expression, so it still bounds the arrays
that use it, and it now carries a type and can be checked with
static_assert. Feature switches (#if), the CSIETYPE/EBCDIC byte
constants read as octets, and the related-constant enum sets stay as
they were.
Diffstat (limited to 'src/trap.c')
| -rw-r--r-- | src/trap.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -64,7 +64,7 @@ static const struct { /** * @brief Trap actions. Index 0 is the EXIT trap and TRAP_ERR the ERR trap. - * NULL means default, an empty string means ignore. + * nullptr means default, an empty string means ignore. */ static char *trap_action[MAXSIG + 2]; @@ -128,7 +128,7 @@ static void on_signal(int sig) { static void set_handler(int sig, void (*handler)(int)) { struct sigaction sa = {.sa_handler = handler}; sigemptyset(&sa.sa_mask); - sigaction(sig, &sa, NULL); + sigaction(sig, &sa, nullptr); } /** @@ -202,10 +202,10 @@ void trap_note(int sig) { /** * @brief Signals a spawned child must have reset to their default action. - * @return The set, or NULL if there are none. + * @return The set, or nullptr if there are none. */ const sigset_t *trap_spawn_defaults(void) { - return have_shell_ignored ? &shell_ignored : NULL; + return have_shell_ignored ? &shell_ignored : nullptr; } /** @@ -220,7 +220,7 @@ static bool ignored_on_entry(int sig) { struct sigaction sa; entry_checked[sig] = true; entry_ignored[sig] = - sigaction(sig, NULL, &sa) == 0 && sa.sa_handler == SIG_IGN; + sigaction(sig, nullptr, &sa) == 0 && sa.sa_handler == SIG_IGN; } return entry_ignored[sig]; } @@ -228,13 +228,13 @@ static bool ignored_on_entry(int sig) { /** * @brief Set, clear or ignore the trap for a signal (or EXIT, or ERR). * @param sig Signal number, 0 for EXIT, TRAP_ERR for ERR. - * @param action Command text. "" to ignore. NULL for the default. + * @param action Command text. "" to ignore. nullptr for the default. */ static void set_trap(int sig, const char *action) { if (sig && sig != TRAP_ERR && ignored_on_entry(sig)) return; free(trap_action[sig]); - trap_action[sig] = action ? xstrdup(action) : NULL; + trap_action[sig] = action ? xstrdup(action) : nullptr; show_parent = false; if (sig == TRAP_ERR) trap_err_set = action && *action; @@ -294,7 +294,7 @@ void trap_reset_child(void) { for (int sig = 0; sig <= TRAP_ERR; sig++) { if (!show_parent) { free(parent_action[sig]); - parent_action[sig] = NULL; + parent_action[sig] = nullptr; } if (!trap_action[sig] || !*trap_action[sig]) continue; @@ -302,7 +302,7 @@ void trap_reset_child(void) { parent_action[sig] = trap_action[sig]; else free(trap_action[sig]); - trap_action[sig] = NULL; + trap_action[sig] = nullptr; if (sig && sig != TRAP_ERR) set_handler(sig, SIG_DFL); } @@ -365,7 +365,7 @@ void trap_run_exit(void) { char *action = trap_action[0]; if (!action) return; - trap_action[0] = NULL; + trap_action[0] = nullptr; if (*action) eval_string(action, 0); free(action); @@ -375,7 +375,7 @@ void trap_run_exit(void) { /** * @brief Name of a signal, without "SIG". - * @return The name, or NULL if the number has none. + * @return The name, or nullptr if the number has none. */ static const char *signal_name(int sig) { if (sig == 0) @@ -386,7 +386,7 @@ static const char *signal_name(int sig) { if (signames[i].sig == sig) return signames[i].name; } - return NULL; + return nullptr; } /** @@ -448,7 +448,7 @@ int builtin_trap(int argc, char **argv) { } return 0; } - const char *action = NULL; + const char *action = nullptr; if (!strcmp(argv[i], "-")) i++; else if (!isdigit((unsigned char)argv[i][0])) |
