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 | |
| 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.
| -rw-r--r-- | DESIGN.md | 11 | ||||
| -rw-r--r-- | src/alias.c | 4 | ||||
| -rw-r--r-- | src/ast.h | 4 | ||||
| -rw-r--r-- | src/builtin.c | 18 | ||||
| -rw-r--r-- | src/builtin_ext.c | 18 | ||||
| -rw-r--r-- | src/complete.c | 2 | ||||
| -rw-r--r-- | src/cond.c | 8 | ||||
| -rw-r--r-- | src/edit_builtin.c | 6 | ||||
| -rw-r--r-- | src/edit_libedit.c | 8 | ||||
| -rw-r--r-- | src/exec.c | 88 | ||||
| -rw-r--r-- | src/expand.c | 24 | ||||
| -rw-r--r-- | src/history.c | 26 | ||||
| -rw-r--r-- | src/interact.c | 2 | ||||
| -rw-r--r-- | src/interact.h | 2 | ||||
| -rw-r--r-- | src/jobs.c | 42 | ||||
| -rw-r--r-- | src/main.c | 10 | ||||
| -rw-r--r-- | src/mvsfmt.c | 28 | ||||
| -rw-r--r-- | src/mvsfmt.h | 8 | ||||
| -rw-r--r-- | src/parser.c | 34 | ||||
| -rw-r--r-- | src/parser.h | 2 | ||||
| -rw-r--r-- | src/pattern.c | 8 | ||||
| -rw-r--r-- | src/printf.c | 8 | ||||
| -rw-r--r-- | src/redir.c | 2 | ||||
| -rw-r--r-- | src/shell.h | 2 | ||||
| -rw-r--r-- | src/sys.h | 2 | ||||
| -rw-r--r-- | src/sys_posix.c | 14 | ||||
| -rw-r--r-- | src/sys_zos.c | 12 | ||||
| -rw-r--r-- | src/trap.c | 26 | ||||
| -rw-r--r-- | src/unparse.c | 14 | ||||
| -rw-r--r-- | src/util.c | 18 | ||||
| -rw-r--r-- | src/var.c | 38 | ||||
| -rw-r--r-- | src/var.h | 2 |
32 files changed, 249 insertions, 242 deletions
@@ -74,8 +74,15 @@ creation and character encoding. `[[fallthrough]]` in a `switch`. Two more, `UNREACHABLE()` and `PRINTFLIKE` for format checking, remain macros in `shell.h` because the standard has no spelling for them yet. -- Constants are `#define`s with a typed value, or anonymous `enum`s for - sets of related integer constants. +- Constants are `constexpr` where a typed constant is better: the + IGGCSI00 work-area offsets and sizes, `MVS_DSN_MAX`, `CSI_WORK`, + `PDS_DIRBLK`. A `constexpr` in C is a constant expression, so it can + still bound an array (`unsigned char work[CSI_WORK]`), give a type to + a value, and be checked with `static_assert`. Feature switches that + `#if` reads, and sets of related integer constants, stay macros and + anonymous `enum`s: `#if` cannot see a `constexpr`. +- `nullptr` everywhere a null pointer constant is meant; `NULL` is not + used. - Warnings: `-Wall -Wextra -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wconversion`, and the tree stays warning-free. diff --git a/src/alias.c b/src/alias.c index bbbbf65..bf1a236 100644 --- a/src/alias.c +++ b/src/alias.c @@ -40,14 +40,14 @@ static size_t alias_hash(const char *s) { /** * @brief Look up an alias. * @param name Candidate command word. - * @return The alias, or NULL if `name` is not one. + * @return The alias, or nullptr if `name` is not one. */ alias *alias_find(const char *name) { for (alias *a = atab[alias_hash(name)]; a; a = a->next) { if (!strcmp(a->name, name)) return a; } - return NULL; + return nullptr; } /** @@ -38,7 +38,7 @@ typedef struct wpart { size_t len; } lit; param *param; - node *cmd; /**< P_CMDSUB; NULL for an empty $() */ + node *cmd; /**< P_CMDSUB; nullptr for an empty $() */ struct wpart *arith; /**< P_ARITH: the expression text */ } u; } wpart; @@ -216,7 +216,7 @@ typedef struct node { } bin; /**< N_AND, N_OR, N_SEQ */ struct node *body; /**< N_NOT, N_BG, N_SUBSHELL, N_GROUP */ struct { - struct node *body; /**< the pipeline, or NULL for none */ + struct node *body; /**< the pipeline, or nullptr for none */ bool posix; /**< `-p`: the POSIX output format */ } time; /**< N_TIME */ wpart *arith; /**< N_ARITH: one P_ARITH part */ diff --git a/src/builtin.c b/src/builtin.c index bf20c8e..8497a0d 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -345,7 +345,7 @@ static int b_shift(int argc, char **argv) { * signal arrived. */ static int b_read(int argc, char **argv) { - static char *default_vars[] = {"REPLY", NULL}; + static char *default_vars[] = {"REPLY", nullptr}; bool raw = false; double timeout = -1; /* seconds; negative: wait for ever */ int i = 1; @@ -374,7 +374,7 @@ static int b_read(int argc, char **argv) { } struct timeval deadline = {0}; if (timeout >= 0) { - gettimeofday(&deadline, NULL); + gettimeofday(&deadline, nullptr); deadline.tv_sec += (time_t)timeout; deadline.tv_usec += (suseconds_t)((timeout - (double)(time_t)timeout) * 1e6); @@ -422,7 +422,7 @@ static int b_read(int argc, char **argv) { if (timeout >= 0) { /* -t: give up (status > 128) if no input arrives in time. */ struct timeval now; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); long ms = (long)(deadline.tv_sec - now.tv_sec) * 1000 + (long)(deadline.tv_usec - now.tv_usec) / 1000; struct pollfd pfd = {.fd = 0, .events = POLLIN}; @@ -556,7 +556,7 @@ static int b_getopts(int argc, char **argv) { if (v && (!parse_long(v, &ind) || ind < 1)) ind = 1; - const char *arg = ind <= nargs ? args[ind - 1] : NULL; + const char *arg = ind <= nargs ? args[ind - 1] : nullptr; if (getopts_off && (!arg || getopts_off >= strlen(arg))) getopts_off = 0; /* the arguments changed under us: start afresh */ if (getopts_off == 0) { @@ -576,8 +576,8 @@ static int b_getopts(int argc, char **argv) { char c = arg[getopts_off++]; char opt_name[2] = {c, '\0'}; const char *result = opt_name; - const char *optval = NULL; - const char *spec = c == ':' ? NULL : strchr(optstring, c); + const char *optval = nullptr; + const char *spec = c == ':' ? nullptr : strchr(optstring, c); bool took_arg = false; if (!spec) { @@ -705,7 +705,7 @@ static bool is_directory(const char *path) { * @param dest The directory asked for. * @param print Set if the result came from a non-empty CDPATH entry, in * which case `cd` prints where it went. - * @return The path to use, or NULL if CDPATH has no match. + * @return The path to use, or nullptr if CDPATH has no match. */ static const char *cdpath_search(const char *dest, bool *print) { const char *cdpath = var_get("CDPATH"); @@ -827,8 +827,8 @@ static bool is_keyword(const char *s) { */ int describe_command(const char *name, bool verbose) { cmdinfo ci; - const char *what = NULL; - const alias *al = alias_count ? alias_find(name) : NULL; + const char *what = nullptr; + const alias *al = alias_count ? alias_find(name) : nullptr; if (al) { if (verbose) { out_printf(&out1, "%s is an alias for %s\n", name, al->value); diff --git a/src/builtin_ext.c b/src/builtin_ext.c index 9b0ee9c..f693552 100644 --- a/src/builtin_ext.c +++ b/src/builtin_ext.c @@ -144,7 +144,7 @@ int builtin_whence(int argc, char **argv) { } const char *path = var_get("PATH"); const char *full = strchr(argv[i], '/') - ? (access(argv[i], X_OK) == 0 ? argv[i] : NULL) + ? (access(argv[i], X_OK) == 0 ? argv[i] : nullptr) : path_search(argv[i], path ? path : "", true); if (full) out_printf(&out1, "%s\n", full); @@ -278,7 +278,7 @@ typedef struct limit { char opt; /**< Option letter. */ int resource; /**< RLIMIT_* value. */ const char *name; /**< Description for `ulimit -a`. */ - const char *unit; /**< Unit name for `ulimit -a`, or NULL. */ + const char *unit; /**< Unit name for `ulimit -a`, or nullptr. */ unsigned scale; /**< Bytes (or items) per unit shown to the user. */ } limit; @@ -297,7 +297,7 @@ static const limit limits[] = { {'m', RLIMIT_RSS, "max memory size", "kbytes", 1024}, #endif #ifdef RLIMIT_NOFILE - {'n', RLIMIT_NOFILE, "open files", NULL, 1}, + {'n', RLIMIT_NOFILE, "open files", nullptr, 1}, #endif #ifdef RLIMIT_STACK {'s', RLIMIT_STACK, "stack size", "kbytes", 1024}, @@ -306,7 +306,7 @@ static const limit limits[] = { {'t', RLIMIT_CPU, "cpu time", "seconds", 1}, #endif #ifdef RLIMIT_NPROC - {'u', RLIMIT_NPROC, "max user processes", NULL, 1}, + {'u', RLIMIT_NPROC, "max user processes", nullptr, 1}, #endif #ifdef RLIMIT_AS {'v', RLIMIT_AS, "virtual memory", "kbytes", 1024}, @@ -349,7 +349,7 @@ int builtin_ulimit(int argc, char **argv) { bool hard = false; bool soft = false; bool all = false; - const limit *l = NULL; + const limit *l = nullptr; int i = 1; for (; i < argc && argv[i][0] == '-' && argv[i][1]; i++) { for (const char *p = argv[i] + 1; *p; p++) { @@ -360,7 +360,7 @@ int builtin_ulimit(int argc, char **argv) { } else if (*p == 'a') { all = true; } else { - const limit *found = NULL; + const limit *found = nullptr; for (size_t k = 0; k < ARRAY_LEN(limits); k++) { if (limits[k].opt == *p) found = &limits[k]; @@ -476,7 +476,7 @@ static int tag_print(const char *path) { */ int builtin_tag(int argc, char **argv) { char mode = 'p'; - const char *codeset = NULL; + const char *codeset = nullptr; int i = 1; for (; i < argc && argv[i][0] == '-' && argv[i][1]; i++) { if (!strcmp(argv[i], "--")) { @@ -487,7 +487,7 @@ int builtin_tag(int argc, char **argv) { if (strchr("ptmbr", *p)) { mode = *p; } else if (*p == 'c') { - codeset = p[1] ? p + 1 : (i + 1 < argc ? argv[++i] : NULL); + codeset = p[1] ? p + 1 : (i + 1 < argc ? argv[++i] : nullptr); if (!codeset) { sh_warn("tag: -c: code set required"); return 2; @@ -510,7 +510,7 @@ int builtin_tag(int argc, char **argv) { status |= tag_print(argv[i]); continue; } - int rc = mode == 'r' ? sys_tag_set(argv[i], NULL, 0) + int rc = mode == 'r' ? sys_tag_set(argv[i], nullptr, 0) : mode == 'b' ? sys_tag_set(argv[i], "BINARY", 0) : sys_tag_set(argv[i], codeset, mode == 't'); if (rc < 0) { diff --git a/src/complete.c b/src/complete.c index c71ed7a..d2e68ef 100644 --- a/src/complete.c +++ b/src/complete.c @@ -89,7 +89,7 @@ static void add_files(candidates *c, const char *dir, const char *shown, return; size_t plen = strlen(prefix); const struct dirent *e; - while ((e = readdir(d)) != NULL) { + while ((e = readdir(d)) != nullptr) { const char *name = e->d_name; if (!has_prefix(name, prefix, plen)) continue; @@ -47,7 +47,7 @@ static const char *operand(const word *w) { * expression? */ static bool is_ere_special(char c) { - return strchr("\\.[]()*+?{}|^$", c) != NULL; + return strchr("\\.[]()*+?{}|^$", c) != nullptr; } /** @@ -65,7 +65,7 @@ static const char *regex_text(const word *w) { sb_init(&sb, &scratch); for (const wpart *p = w->parts; p; p = p->next) { wpart one = *p; - one.next = NULL; + one.next = nullptr; const char *s = expand_string(&one, 0); if (!p->quoted) { sb_puts(&sb, s); @@ -94,7 +94,7 @@ static int regex_match(const char *s, const char *re) { sh_warn("[[: %s: %s", re, msg); return 2; } - rc = regexec(&rx, s, 0, NULL, 0); + rc = regexec(&rx, s, 0, nullptr, 0); regfree(&rx); return rc == 0 ? 0 : 1; } @@ -111,7 +111,7 @@ static bool unary(char op, const char *arg) { case 'o': return option_is_set(arg) == 1; case 'v': - return var_get(arg) != NULL; + return var_get(arg) != nullptr; default: return test_unary(op, arg); } diff --git a/src/edit_builtin.c b/src/edit_builtin.c index aee4d8e..4b8904b 100644 --- a/src/edit_builtin.c +++ b/src/edit_builtin.c @@ -546,7 +546,7 @@ static int bind_keys(const char *s, size_t len, char *out, size_t *outlen) { int edit_bind(const char *spec) { const char *eq = strchr(spec, '='); - if (eq == NULL) { + if (eq == nullptr) { sh_warn("bind: %s: expected keys=action", spec); return -1; } @@ -1496,7 +1496,7 @@ static bool edit_key(int k) { * prompt that is redrawn. * @param len Receives the length of the line. * @return The line, NUL-terminated and without a newline, valid until the - * next call. NULL at end of input (`^D` on an empty line). + * next call. nullptr at end of input (`^D` on an empty line). */ char *edit_readline(const char *prompt, size_t *len) { const char *last = strrchr(prompt, '\n'); @@ -1548,7 +1548,7 @@ char *edit_readline(const char *prompt, size_t *len) { ob_flush(); raw_off(); if (eof) - return NULL; + return nullptr; ed.buf[ed.len] = '\0'; *len = ed.len; return ed.buf; diff --git a/src/edit_libedit.c b/src/edit_libedit.c index 6a32db7..d9282fc 100644 --- a/src/edit_libedit.c +++ b/src/edit_libedit.c @@ -68,7 +68,7 @@ bool edit_usable(void) { * @param prompt Text to show before the line. * @param len Receives the length of the line. * @return The line without its newline, valid until the next call; - * NULL at end of input. + * nullptr at end of input. */ char *edit_readline(const char *prompt, size_t *len) { static char *line; @@ -77,12 +77,12 @@ char *edit_readline(const char *prompt, size_t *len) { el = el_init("zash", stdin, stderr, stderr); el_hist = history_init(); if (!el || !el_hist) - return NULL; + return nullptr; history(el_hist, &ev, H_SETSIZE, 100000); el_set(el, EL_HIST, history, el_hist); el_set(el, EL_PROMPT, prompt_cb); el_set(el, EL_SIGNAL, 0); - el_source(el, NULL); + el_source(el, nullptr); } el_set(el, EL_EDITOR, opt.vi ? "vi" : "emacs"); history(el_hist, &ev, H_CLEAR); @@ -108,7 +108,7 @@ char *edit_readline(const char *prompt, size_t *len) { trap_poll(); /* ^C abandons the line and does not return */ continue; } - return NULL; + return nullptr; } } @@ -110,7 +110,7 @@ static cmdent *ctab[CTAB_SIZE]; * @brief Find a name in the command table. * @param name Command name. * @param create Add an empty entry if it is not there. - * @return The entry, or NULL. + * @return The entry, or nullptr. */ static cmdent *cmd_lookup(const char *name, bool create) { unsigned h = 5381; @@ -122,7 +122,7 @@ static cmdent *cmd_lookup(const char *name, bool create) { return e; } if (!create) - return NULL; + return nullptr; size_t len = strlen(name) + 1; cmdent *e = xmalloc(sizeof *e + len); *e = (cmdent){.next = *bucket, .hash = h}; @@ -138,7 +138,7 @@ void hash_clear(void) { for (size_t i = 0; i < CTAB_SIZE; i++) { for (cmdent *e = ctab[i]; e; e = e->next) { free(e->path); - e->path = NULL; + e->path = nullptr; } } } @@ -208,10 +208,10 @@ static int eval_time(const node *n, unsigned flags) { struct timeval t1; getrusage(RUSAGE_SELF, &s0); getrusage(RUSAGE_CHILDREN, &c0); - gettimeofday(&t0, NULL); + gettimeofday(&t0, nullptr); int status = n->u.time.body ? eval_node(n->u.time.body, flags & ~EV_EXIT) : 0; - gettimeofday(&t1, NULL); + gettimeofday(&t1, nullptr); getrusage(RUSAGE_SELF, &s1); getrusage(RUSAGE_CHILDREN, &c1); bool posix = n->u.time.posix; @@ -319,7 +319,7 @@ static char **zos_environ(char **envp, const char *name, bool foreground) { memcpy(env, envp, n * sizeof *env); for (int i = 0; i < nadd; i++) env[n + (size_t)i] = add[i]; - env[n + (size_t)nadd] = NULL; + env[n + (size_t)nadd] = nullptr; return env; } @@ -336,7 +336,7 @@ static void path_changed(const char *value) { * @param name File name without a slash. * @param path Colon-separated directories. * @param executable Require a regular file with execute permission. - * @return The full path in scratch memory, or NULL. + * @return The full path in scratch memory, or nullptr. */ char *path_search(const char *name, const char *path, bool executable) { size_t nlen = strlen(name); @@ -356,7 +356,7 @@ char *path_search(const char *name, const char *path, bool executable) { (!executable || (st.st_mode & 0111))) return full; if (!colon) - return NULL; + return nullptr; p = colon + 1; } } @@ -470,7 +470,7 @@ bool func_unset(const char *name) { if (!e || !e->fn) return false; func_unref(e->fn); - e->fn = NULL; + e->fn = nullptr; return true; } @@ -555,21 +555,21 @@ pid_t fork_shell(void) { * (ENOEXEC): the interpreter named on its `#!` line, or this shell. * @param path The file. * @param argv The arguments it was to be run with. - * @return The new vector in scratch memory, or NULL if the file is not + * @return The new vector in scratch memory, or nullptr if the file is not * a script. */ static char **script_argv(const char *path, char **argv) { char head[256]; int fd = open(path, O_RDONLY); if (fd < 0) - return NULL; + return nullptr; ssize_t n = read(fd, head, sizeof head - 1); close(fd); if (n < 0) - return NULL; + return nullptr; if (memchr(head, '\0', (size_t)n)) { errno = ENOEXEC; /* a binary we cannot run, not a script */ - return NULL; + return nullptr; } head[n] = '\0'; @@ -593,7 +593,7 @@ static char **script_argv(const char *path, char **argv) { alen--; if (!*interp) { errno = ENOEXEC; - return NULL; + return nullptr; } nv[k++] = arena_strndup(&scratch, interp, strlen(interp)); if (alen) @@ -604,7 +604,7 @@ static char **script_argv(const char *path, char **argv) { nv[k++] = (char *)path; for (int i = 1; i < argc; i++) nv[k++] = argv[i]; - nv[k] = NULL; + nv[k] = nullptr; return nv; } @@ -642,7 +642,7 @@ static int exec_error(const char *name, int err) { void shell_exec(char **argv, char **envp) { cmdinfo ci; find_command(argv[0], &ci, FC_NOFUNC); - const char *path = ci.kind == C_EXTERNAL ? ci.path : NULL; + const char *path = ci.kind == C_EXTERNAL ? ci.path : nullptr; if (!path && !strchr(argv[0], '/')) { const char *search = var_get("PATH"); path = path_search(argv[0], search ? search : default_path, true); @@ -753,12 +753,12 @@ static void simple_prep(node *n, simple_cmd *sc) { sc->cmd = (cmdinfo){0}; cmdsub_ran = false; cur_lineno = n->lineno; - sc->atext = NULL; + sc->atext = nullptr; sc->nassign = 0; sc->argv = expand_words(n->u.simple.args, &sc->argc); if (!sc->argc) return; - path_override = NULL; + path_override = nullptr; if (n->u.simple.assigns) { /* Expanded once, here, after the words (POSIX order). */ for (const word *w = n->u.simple.assigns; w; w = w->next) @@ -779,7 +779,7 @@ static void simple_prep(node *n, simple_cmd *sc) { for (;;) { find_command(sc->argv[0], &sc->cmd, flags); if (sc->cmd.kind != C_BUILTIN || sc->cmd.bi->fn != builtin_command) { - path_override = NULL; + path_override = nullptr; return; } /* "command [-p] name ...": look `name` up afresh, minus functions. */ @@ -792,7 +792,7 @@ static void simple_prep(node *n, simple_cmd *sc) { if (i < sc->argc && !strcmp(sc->argv[i], "--")) i++; if (i >= sc->argc || sc->argv[i][0] == '-') { - path_override = NULL; + path_override = nullptr; return; /* -v, -V or nothing: the builtin handles it */ } sc->argv += i; @@ -914,7 +914,7 @@ static void tag_prefix_end(const tag_mode saved[3], int in, int out) { * @param flags EV_EXIT allows replacing the shell with exec. * @param in Descriptor for its stdin, or -1. * @param out Descriptor for its stdout, or -1. - * @param async When not NULL, receives the pid and the command is not + * @param async When not nullptr, receives the pid and the command is not * waited for (pipeline stages, `&`, command substitution). * @return The exit status. 0 for an async launch. */ @@ -944,7 +944,7 @@ static int run_external(simple_cmd *sc, unsigned flags, int in, int out, } /* Under job control a foreground command is a job of its own. */ job *jb = - !async && jc_active() && !job_launching ? job_begin(n, true) : NULL; + !async && jc_active() && !job_launching ? job_begin(n, true) : nullptr; int status = 0; pid_t pid = spawn_command(sc->cmd.path, sc->argv, envp, &plan, &status); plan_close(&plan); @@ -1080,7 +1080,7 @@ int call_function(func *fn, int argc, char **argv, unsigned flags) { fn->refs++; func_depth++; loop_depth = 0; - shellparam = (shparam){argc - 1, argv + 1, NULL}; + shellparam = (shparam){argc - 1, argv + 1, nullptr}; if (setjmp(jl.buf) == 0) { exc_handler = &jl; eval_node(fn->body, flags & EV_TESTED); @@ -1149,7 +1149,7 @@ static int simple_run(simple_cmd *sc, unsigned flags) { case C_FUNC: return run_function(sc, flags); case C_EXTERNAL: - return run_external(sc, flags, -1, -1, NULL); + return run_external(sc, flags, -1, -1, nullptr); case C_NOTFOUND: { /* The message belongs on the command's stderr, not ours. */ redirsave rs; @@ -1370,7 +1370,7 @@ static void read_all(int fd, strbuf *sb); * @param st The stages. * @param nc Number of commands. * @param total Number of stage slots (one more when capturing). - * @param jb The job, under job control. Else NULL. + * @param jb The job, under job control. Else nullptr. * @return Status of the last command, or with `pipefail` of the last one * that failed. */ @@ -1414,7 +1414,7 @@ static int pipe_finish(stage *st, int nc, int total, job *jb) { * * @param n The N_PIPE node. * @param flags Evaluation flags. - * @param cap Where to collect the output, or NULL. + * @param cap Where to collect the output, or nullptr. * @return The pipeline's exit status. */ static int eval_pipe(node *n, unsigned flags, strbuf *cap) { @@ -1448,7 +1448,7 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) { * every stage is a process, the last included: a stage running inside * the shell could not be stopped with the rest of the job. */ - job *jb = !cap && jc_active() && !job_launching ? job_begin(n, true) : NULL; + job *jb = !cap && jc_active() && !job_launching ? job_begin(n, true) : nullptr; varscope vs; scope_push(&vs, true, false); bool any_deferred = false; @@ -1468,7 +1468,7 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) { if (st[i].deferred) run_deferred(st, total, i, !cap); } - sigaction(SIGPIPE, &old, NULL); + sigaction(SIGPIPE, &old, nullptr); } if (cap) read_all(st[nc].in, cap); @@ -1506,7 +1506,7 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) { if (st[i].deferred) run_deferred(st, nc, i, true); } - sigaction(SIGPIPE, &old, NULL); + sigaction(SIGPIPE, &old, nullptr); } if (!last_started) { redirsave rs; @@ -1525,10 +1525,10 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) { exc_handler = prev; if (raised) { - pipe_finish(st, nc, total, NULL); + pipe_finish(st, nc, total, nullptr); exc_raise(exc_code); } - return pipe_finish(st, nc, total, NULL); + return pipe_finish(st, nc, total, nullptr); } /* ---- background commands --------------------------------------------- */ @@ -1559,7 +1559,7 @@ static int eval_background(node *body) { * keeps its stdin and signal settings: it is the group, not ignored * signals, that protects it from the keyboard. */ - job *jb = jc_active() ? job_begin(body, false) : NULL; + job *jb = jc_active() ? job_begin(body, false) : nullptr; if (prepped && sc.argc && sc.cmd.kind == C_EXTERNAL) { if (jb) { run_external(&sc, 0, -1, -1, &pid); @@ -1571,8 +1571,8 @@ static int eval_background(node *body) { sigaction(SIGINT, &ignore, &old_int); sigaction(SIGQUIT, &ignore, &old_quit); run_external(&sc, 0, null, -1, &pid); - sigaction(SIGINT, &old_int, NULL); - sigaction(SIGQUIT, &old_quit, NULL); + sigaction(SIGINT, &old_int, nullptr); + sigaction(SIGQUIT, &old_quit, nullptr); if (null >= 0) close(null); } @@ -1586,8 +1586,8 @@ static int eval_background(node *body) { pid = fork_shell(); if (pid == 0) { if (!jb) { - sigaction(SIGINT, &ignore, NULL); - sigaction(SIGQUIT, &ignore, NULL); + sigaction(SIGINT, &ignore, nullptr); + sigaction(SIGQUIT, &ignore, nullptr); int null = open("/dev/null", O_RDONLY); if (null >= 0) { dup2(null, 0); @@ -1626,7 +1626,7 @@ static void read_all(int fd, strbuf *sb) { /** * @brief Run a command substitution in a forked subshell (the general case). * @param n The command. - * @param sc Its prepared form if it is a simple command, else NULL. + * @param sc Its prepared form if it is a simple command, else nullptr. * @param sb Receives the output. * @return The exit status. */ @@ -1661,7 +1661,7 @@ static int cmdsub_collect(node *n, strbuf *sb) { if (n->kind == N_PIPE) return eval_pipe(n, 0, sb); if (n->kind != N_SIMPLE) - return cmdsub_fork(n, NULL, sb); + return cmdsub_fork(n, nullptr, sb); const redir *r = n->redirs; if (!n->u.simple.args && !n->u.simple.assigns && r && !r->next && @@ -1709,7 +1709,7 @@ static int cmdsub_collect(node *n, strbuf *sb) { /** * @brief Run a command substitution. - * @param n The command, or NULL for an empty `$()`. + * @param n The command, or nullptr for an empty `$()`. * @param lenp Receives the length of the output. * @return The output with trailing newlines removed, in scratch memory. */ @@ -1722,7 +1722,7 @@ char *cmdsub_run(node *n, size_t *lenp) { * happens to be half launched (a pipeline stage's arguments). */ job *launching = job_launching; varscope vs; - job_launching = NULL; + job_launching = nullptr; scope_push(&vs, true, false); status = cmdsub_collect(n, &sb); scope_pop(); @@ -1840,7 +1840,7 @@ static int eval_subshell(node *n, unsigned flags) { if (!ok) return exitstatus; } - job *jb = jc_active() && !job_launching ? job_begin(n, true) : NULL; + job *jb = jc_active() && !job_launching ? job_begin(n, true) : nullptr; pid_t pid = fork_shell(); if (pid) { if (!jb) @@ -1869,7 +1869,7 @@ static int eval_subshell(node *n, unsigned flags) { * a failing command the ERR trap and `errexit` are applied, and pending * trap actions run. * - * @param n The command, or NULL for an empty one. + * @param n The command, or nullptr for an empty one. * @param flags EV_EXIT if nothing follows the command, EV_TESTED if its * status is being tested. * @return The exit status, also left in `$?`. @@ -1904,7 +1904,7 @@ int eval_node(node *n, unsigned flags) { break; } case N_PIPE: - status = eval_pipe(n, flags, NULL); + status = eval_pipe(n, flags, nullptr); leaf = true; break; case N_SUBSHELL: @@ -2053,7 +2053,7 @@ int run_input(unsigned flags) { skip_kind = SKIP_NONE; loop_depth = saved_loop; dot_depth = 0; - job_launching = NULL; + job_launching = nullptr; } exc_handler = &jl; if (flags & RI_TOP) diff --git a/src/expand.c b/src/expand.c index 515a7b1..943d2bf 100644 --- a/src/expand.c +++ b/src/expand.c @@ -60,7 +60,7 @@ static const char empty_string[] = ""; /** * @brief Append a finished field to the argument vector. * @param x Expansion state. - * @param s The field (scratch memory), or NULL to terminate the vector. + * @param s The field (scratch memory), or nullptr to terminate the vector. */ static void field_add(expansion *x, const char *s) { if (x->argc + 1 >= x->cap) { @@ -295,7 +295,7 @@ static size_t expand_tilde(expansion *x, const char *s, size_t n, bool assign, } else { const struct passwd *pw = getpwnam(arena_strndup(&scratch, s + 1, e - 1)); - home = pw ? pw->pw_dir : NULL; + home = pw ? pw->pw_dir : nullptr; } if (!home) return 0; @@ -397,7 +397,7 @@ static void expand_all_params(expansion *x, char which, bool quoted) { * @param c The parameter character. * @param buf Work space for numbers. * @param size Size of `buf`. - * @return The value, or NULL if it is unset (`$!` before any `&`). + * @return The value, or nullptr if it is unset (`$!` before any `&`). */ static const char *special_value(char c, char *buf, size_t size) { switch (c) { @@ -410,19 +410,19 @@ static const char *special_value(char c, char *buf, size_t size) { return fmt_int(shellparam.n, buf); case '!': if (!last_bg_pid) - return NULL; + return nullptr; snprintf(buf, size, "%ld", (long)last_bg_pid); return buf; case '-': return option_letters(); default: - return NULL; + return nullptr; } } /** * @brief Current value of a parameter of any kind. - * @return The value, or NULL if the parameter is unset. + * @return The value, or nullptr if the parameter is unset. */ static const char *param_value(const param *pm, char *buf, size_t size) { switch (pm->type) { @@ -431,11 +431,11 @@ static const char *param_value(const param *pm, char *buf, size_t size) { case PT_POS: if (pm->pos == 0) return arg0; - return pm->pos <= shellparam.n ? shellparam.p[pm->pos - 1] : NULL; + return pm->pos <= shellparam.n ? shellparam.p[pm->pos - 1] : nullptr; case PT_SPECIAL: return special_value(pm->special, buf, size); } - return NULL; + return nullptr; } /** @@ -523,7 +523,7 @@ static void expand_param(expansion *x, const param *pm, bool quoted) { return; } val = shellparam.n ? join_params(pm->special == '*' ? ifs_first : ' ') - : NULL; + : nullptr; } else { val = param_value(pm, buf, sizeof buf); } @@ -668,7 +668,7 @@ static void expand_word(expansion *x, const wpart *p) { * * @param list The words. * @param argc Receives the number of fields. - * @return A NULL-terminated vector in scratch memory. + * @return A nullptr-terminated vector in scratch memory. */ char **expand_words(const word *list, int *argc) { expansion x = {.mode = X_FIELDS}; @@ -684,7 +684,7 @@ char **expand_words(const word *list, int *argc) { field_end(&x); x.sep = SEP_NONE; } - field_add(&x, NULL); + field_add(&x, nullptr); *argc = x.argc - 1; return x.argv; } @@ -731,7 +731,7 @@ char *expand_assign(const word *w) { emit_assign_lit(&x, p->u.lit.s, p->u.lit.len, false, !p->next); } else { wpart one = *p; - one.next = NULL; + one.next = nullptr; expand_parts(&x, &one); } } diff --git a/src/history.c b/src/history.c index 2cc536d..26846c3 100644 --- a/src/history.c +++ b/src/history.c @@ -46,10 +46,10 @@ int hist_count(void) { /** * @brief Fetch an entry. * @param index 0 for the oldest entry, hist_count()-1 for the newest. - * @return The command text, or NULL if `index` is out of range. + * @return The command text, or nullptr if `index` is out of range. */ const char *hist_entry(int index) { - return index >= 0 && index < hist_n ? hist[index] : NULL; + return index >= 0 && index < hist_n ? hist[index] : nullptr; } /** @brief Remove the newest entry (used by `fc` to erase itself). */ @@ -110,12 +110,12 @@ void hist_add(const char *line, size_t len, bool append) { * @brief Read a whole file into memory. * @param path File name. * @param lenp Receives the length. - * @return Heap buffer (NUL-terminated), or NULL if it cannot be read. + * @return Heap buffer (NUL-terminated), or nullptr if it cannot be read. */ static char *read_file(const char *path, size_t *lenp) { int fd = sys_open(path, O_RDONLY, 0); if (fd < 0) - return NULL; + return nullptr; size_t cap = 4096; size_t len = 0; char *buf = xmalloc(cap); @@ -139,7 +139,7 @@ static char *read_file(const char *path, size_t *lenp) { void hist_init(void) { const char *path = var_get("HISTFILE"); size_t len; - char *text = path && *path ? read_file(path, &len) : NULL; + char *text = path && *path ? read_file(path, &len) : nullptr; if (!text) return; for (char *p = text; *p;) { @@ -234,8 +234,8 @@ static int hist_run(const char *text) { /** * @brief `fc -s [old=new] [first]`: re-run a command, optionally with * one substitution. - * @param old_new The "old=new" operand, or NULL. - * @param first Which command, or NULL for the previous one. + * @param old_new The "old=new" operand, or nullptr. + * @param first Which command, or nullptr for the previous one. * @return The command's exit status, or 1 if there is no such command. */ static int fc_substitute(const char *old_new, const char *first) { @@ -250,7 +250,7 @@ static int fc_substitute(const char *old_new, const char *first) { const char *eq = strchr(old_new, '='); size_t olen = (size_t)(eq - old_new); const char *at = - olen ? strstr(text, arena_strndup(&scratch, old_new, olen)) : NULL; + olen ? strstr(text, arena_strndup(&scratch, old_new, olen)) : nullptr; if (!at) return hist_run(text); strbuf sb; @@ -299,7 +299,7 @@ static int fc_edit(const char *editor, int lo, int hi) { sb_puts(&cmd, file); int status = eval_string(sb_cstr(&cmd), 0); size_t len = 0; - char *text = status == 0 ? read_file(file, &len) : NULL; + char *text = status == 0 ? read_file(file, &len) : nullptr; unlink(file); if (!text) return status ? status : 1; @@ -326,7 +326,7 @@ int builtin_fc(int argc, char **argv) { bool nonum = false; bool reverse = false; bool subst = false; - const char *editor = NULL; + const char *editor = nullptr; int i = 1; for (; i < argc && argv[i][0] == '-' && argv[i][1]; i++) { long num; @@ -346,7 +346,7 @@ int builtin_fc(int argc, char **argv) { } else if (*p == 's') { subst = true; } else if (*p == 'e') { - editor = p[1] ? p + 1 : i + 1 < argc ? argv[++i] : NULL; + editor = p[1] ? p + 1 : i + 1 < argc ? argv[++i] : nullptr; if (!editor) { sh_warn("fc: -e: editor name expected"); return 2; @@ -371,8 +371,8 @@ int builtin_fc(int argc, char **argv) { subst = true; if (subst) { const char *old_new = - i < argc && strchr(argv[i], '=') ? argv[i++] : NULL; - return fc_substitute(old_new, i < argc ? argv[i] : NULL); + i < argc && strchr(argv[i], '=') ? argv[i++] : nullptr; + return fc_substitute(old_new, i < argc ? argv[i] : nullptr); } if (newest < 0) { if (!list) diff --git a/src/interact.c b/src/interact.c index 4c89a60..4311596 100644 --- a/src/interact.c +++ b/src/interact.c @@ -116,7 +116,7 @@ static char *prompt_escapes(const char *raw) { sb_putc(&sb, '\n'); break; case 'S': { /* z/OS system name; elsewhere the short host name */ - const char *sys = SYS_MVS ? sys_info(SI_SYSNAME) : NULL; + const char *sys = SYS_MVS ? sys_info(SI_SYSNAME) : nullptr; if (!sys) { if (gethostname(host, sizeof host) < 0) host[0] = '\0'; diff --git a/src/interact.h b/src/interact.h index 10aa425..09a5393 100644 --- a/src/interact.h +++ b/src/interact.h @@ -33,7 +33,7 @@ void hist_save(void); * Both editors define these two functions, where they are documented. * edit_usable() says whether lines can be edited on this terminal; * edit_readline() reads one line and returns it without its newline, in - * storage it owns, or NULL at end of input. + * storage it owns, or nullptr at end of input. */ bool edit_usable(void); char *edit_readline(const char *prompt, size_t *len); @@ -49,7 +49,7 @@ typedef struct job { pid_t pgid; /**< Its process group, or 0 if it has none of its own. */ proc *procs; int nprocs; - char *text; /**< Command text for listings; may be NULL. */ + char *text; /**< Command text for listings; may be nullptr. */ bool announce; /**< Changed state; tell the user before the next prompt. */ } job; @@ -62,7 +62,7 @@ job *job_list; /** * @brief The job that processes created right now belong to. * - * Set between job_begin() and the end of launching. NULL otherwise, + * Set between job_begin() and the end of launching. nullptr otherwise, * including whenever job control is off. */ job *job_launching; @@ -134,7 +134,7 @@ int wait_fg(pid_t pid) { /** * @brief Create an empty job and put it at the head of the table. - * @param text Command text (ownership passes to the job), or NULL. + * @param text Command text (ownership passes to the job), or nullptr. * @return The new job. */ static job *job_new(char *text) { @@ -161,7 +161,7 @@ static void job_free(job *j) { } } if (job_launching == j) - job_launching = NULL; + job_launching = nullptr; free(j->procs); free(j->text); free(j); @@ -365,7 +365,7 @@ void jobs_notify(void) { * POSIX asks. * * @param pid The child. - * @param n The command, for the listing text. May be NULL. + * @param n The command, for the listing text. May be nullptr. */ void jobs_add(pid_t pid, const node *n) { job *j = job_new(node_text(n)); @@ -384,7 +384,7 @@ void jobs_add(pid_t pid, const node *n) { void jobs_forget(void) { while (job_list) job_free(job_list); - job_launching = NULL; + job_launching = nullptr; jc_on = false; opt.monitor = false; } @@ -543,7 +543,7 @@ void job_child_setup(void) { * number if the job stopped or was killed. */ int job_wait_fg(job *j) { - job_launching = NULL; + job_launching = nullptr; if (!j->nprocs) return 0; if (jc_on && j->pgid) { @@ -553,7 +553,7 @@ int job_wait_fg(job *j) { kill(-j->pgid, SIGCONT); } for (;;) { - proc *p = NULL; + proc *p = nullptr; for (int i = 0; i < j->nprocs && !p; i++) { if (!j->procs[i].done && !j->procs[i].stopped) p = &j->procs[i]; @@ -631,7 +631,7 @@ int job_status_of(const job *j, pid_t pid) { */ void job_release(job *j) { if (job_launching == j) - job_launching = NULL; + job_launching = nullptr; if (!j->nprocs || job_get_state(j) == JOB_DONE) job_free(j); } @@ -644,7 +644,7 @@ void job_release(job *j) { * @param j The job. */ void job_end_bg(job *j) { - job_launching = NULL; + job_launching = nullptr; if (!j->nprocs) { job_free(j); return; @@ -663,19 +663,19 @@ void job_end_bg(job *j) { * * `%N` is job number N. `%%`, `%+` and `%` the current job. `%-` the * previous job. `%text` a job whose command starts with `text`. `%?text` - * a job whose command contains `text`. NULL selects the current job. + * a job whose command contains `text`. nullptr selects the current job. * - * @param spec The specification, or NULL. - * @return The job, or NULL if there is no such job. + * @param spec The specification, or nullptr. + * @return The job, or nullptr if there is no such job. */ static job *job_find(const char *spec) { if (!spec || !strcmp(spec, "%") || !strcmp(spec, "%%") || !strcmp(spec, "%+")) return job_list; if (!strcmp(spec, "%-")) - return job_list ? job_list->next : NULL; + return job_list ? job_list->next : nullptr; if (spec[0] != '%') - return NULL; + return nullptr; spec++; long id; if (parse_long(spec, &id)) { @@ -683,7 +683,7 @@ static job *job_find(const char *spec) { if (j->id == id) return j; } - return NULL; + return nullptr; } bool anywhere = spec[0] == '?'; if (anywhere) @@ -692,11 +692,11 @@ static job *job_find(const char *spec) { for (job *j = job_list; j; j = j->next) { if (!j->text) continue; - if (anywhere ? strstr(j->text, spec) != NULL + if (anywhere ? strstr(j->text, spec) != nullptr : !strncmp(j->text, spec, len)) return j; } - return NULL; + return nullptr; } /** @@ -781,7 +781,7 @@ int builtin_wait(int argc, char **argv) { } int status = 0; for (int i = 1; i < argc; i++) { - job *j = NULL; + job *j = nullptr; if (argv[i][0] == '%') { j = job_find(argv[i]); } else { @@ -902,7 +902,7 @@ int builtin_fg(int argc, char **argv) { sh_warn("fg: no job control"); return 2; } - job *j = job_find(argc > 1 ? argv[1] : NULL); + job *j = job_find(argc > 1 ? argv[1] : nullptr); if (!j || job_get_state(j) == JOB_DONE) { sh_warn("fg: %s: no such job", argc > 1 ? argv[1] : "current"); return 1; @@ -934,7 +934,7 @@ int builtin_bg(int argc, char **argv) { int status = 0; int i = 1; do { - job *j = job_find(i < argc ? argv[i] : NULL); + job *j = job_find(i < argc ? argv[i] : nullptr); if (!j || job_get_state(j) == JOB_DONE) { sh_warn("bg: %s: no such job", i < argc ? argv[i] : "current"); status = 1; @@ -260,7 +260,7 @@ const char *shell_path(void) { path = full; } else { const char *search = var_get("PATH"); - char *found = search ? path_search(name, search, true) : NULL; + char *found = search ? path_search(name, search, true) : nullptr; path = found ? xstrdup(found) : "/bin/sh"; } return path; @@ -287,7 +287,7 @@ void exit_shell(int status) { code = exitstatus; /* the trap called exit itself */ } } - exc_handler = NULL; + exc_handler = nullptr; if (!in_subshell) { interact_exit(); jc_exit(); @@ -407,8 +407,8 @@ static void usage_print(output *o, bool full) { */ int main(int argc, char **argv) { jmploc jl; - const char *volatile script = NULL; - const char *volatile command = NULL; + const char *volatile script = nullptr; + const char *volatile command = nullptr; volatile bool in_args = false; /* read after longjmp: must be volatile */ bool ignored = false; @@ -459,7 +459,7 @@ int main(int argc, char **argv) { arg0 = script; } in_args = false; - shellparam = (shparam){argc - i, argv + i, NULL}; + shellparam = (shparam){argc - i, argv + i, nullptr}; if (!command && !script) { opt.stdin_cmds = true; diff --git a/src/mvsfmt.c b/src/mvsfmt.c index 8424ac8..dc268b0 100644 --- a/src/mvsfmt.c +++ b/src/mvsfmt.c @@ -138,15 +138,15 @@ static void put32(unsigned char *p, uint32_t v) { * | 152 | 2 | CSINUMEN | number of field names | * | 154 | 8 | CSIFLDNM | field names | */ -#define CSIFILTK 0 -#define CSIDTYPS 132 -#define CSIRESUM 149 -#define CSIS1CAT 150 -#define CSINUMEN 152 -#define CSIFLDNM 154 +constexpr unsigned CSIFILTK = 0; /**< +0, length of the filter key */ +constexpr unsigned CSIDTYPS = 132; /**< entry types to return */ +constexpr unsigned CSIRESUM = 149; /**< Y: return error information */ +constexpr unsigned CSIS1CAT = 150; /**< Y: search one catalog only */ +constexpr unsigned CSINUMEN = 152; /**< number of field names */ +constexpr unsigned CSIFLDNM = 154; /**< field names, 8 each */ /* Return work area, the first field of it (see csi_parse()). */ -#define CSIREQLN 4 +constexpr unsigned CSIREQLN = 4; /**< length of the entry that failed */ /* * Return work area: CSIUSRLN +0 (4, set by the caller), CSIREQLN +4, @@ -156,12 +156,12 @@ static void put32(unsigned char *p, uint32_t v) { * X'40') or, with halfword lengths, CSITOTLN (2) counting itself, two * reserved bytes, one length per field and the fields. */ -#define CSIUSDLN 8 -#define CSI_FIRST 14 -#define CSIE_NAME 2 -#define CSIE_FIXED 46 -#define CSIE_RETINFO 50 -#define CSIENTER 0x40 /* CSIEFLAG: error, return information follows */ +constexpr unsigned CSIUSDLN = 8; /**< bytes of return information used */ +constexpr unsigned CSI_FIRST = 14; /**< offset of the first entry */ +constexpr unsigned CSIE_NAME = 2; /**< name, within an entry */ +constexpr unsigned CSIE_FIXED = 46; /**< bytes before the lengths */ +constexpr unsigned CSIE_RETINFO = 50; /**< bytes of an entry with return info */ +constexpr unsigned char CSIENTER = 0x40; /**< CSIEFLAG: error, return info follows */ #define EB_ZERO 0xf0 /* CSIETYPE of a catalog entry, EBCDIC '0' */ #define EB_Y 0xe8 /* EBCDIC 'Y' */ @@ -299,7 +299,7 @@ bool csi_parse(const unsigned char *work, size_t worklen, mvs_name_fn *fn, * at -- and a broad filter on a big catalog is the one way this feature * can put real work on catalog management. */ -#define CSI_MAX_CALLS 3 +constexpr int CSI_MAX_CALLS = 3; /**< searches before giving up */ /** * @brief Search the catalog: build the criteria, call, decode, and diff --git a/src/mvsfmt.h b/src/mvsfmt.h index 9a6e845..4cb3201 100644 --- a/src/mvsfmt.h +++ b/src/mvsfmt.h @@ -20,7 +20,7 @@ #include <stdint.h> /** @brief Longest data set name. */ -#define MVS_DSN_MAX 44 +constexpr unsigned MVS_DSN_MAX = 44; /** @brief IBM-1047 to ISO8859-1, with z/OS's NL/LF assignment. */ extern const unsigned char mvs_e2a[256]; @@ -43,9 +43,9 @@ typedef void mvs_name_fn(const char *name, char type, void *arg); /* ---- Catalog Search Interface ----------------------------------------- */ /** @brief Selection criteria with one field name (CSIFIELD). */ -#define CSI_FIELD_LEN 162 +constexpr unsigned CSI_FIELD_LEN = 162; /** @brief Smallest work area worth passing. */ -#define CSI_WORK_MIN 1024 +constexpr unsigned CSI_WORK_MIN = 1024; /** * @brief The three areas of a CSI call, as IGGCSI00 sees them. @@ -78,7 +78,7 @@ bool csi_search(const char *filter, csi_area *a, csi_call_fn *call, void *ctx, /* ---- PDS directories and the TIOT -------------------------------------- */ /** @brief Size of a PDS directory block. */ -#define PDS_DIRBLK 256 +constexpr unsigned PDS_DIRBLK = 256; bool pds_parse_block(const unsigned char *blk, mvs_name_fn *fn, void *arg, bool *end); diff --git a/src/parser.c b/src/parser.c index 9303130..28ea5b6 100644 --- a/src/parser.c +++ b/src/parser.c @@ -134,7 +134,7 @@ static node *parse_substring(const char *s, size_t len); void parser_reset(void) { in_cond = false; tok_pushed = false; - here_head = NULL; + here_head = nullptr; here_tail = &here_head; } @@ -195,7 +195,7 @@ static void read_parts(pbuild *b, lex_mode mode, bool litq); * @brief Start building a word. */ static void pb_init(pbuild *b) { - b->head = NULL; + b->head = nullptr; b->tail = &b->head; sb_init(&b->lit, pa); b->litq = false; @@ -291,7 +291,7 @@ static param *new_param(const char *name, size_t nlen) { /** * @brief Read the name that follows `$` when it is not in braces. - * @return The parameter, or NULL if `$` is not followed by a name (it + * @return The parameter, or nullptr if `$` is not followed by a name (it * is then an ordinary character). */ static param *read_param_name(int c, bool braced) { @@ -401,7 +401,7 @@ static void parse_braced_param(pbuild *b, bool q, bool dq) { * * Recursing into the parser (and not scanning for the closing * parenthesis) is what makes `$(case x in x) ;; esac)` work. - * @return The command, or NULL if the substitution is empty. + * @return The command, or nullptr if the substitution is empty. */ static node *parse_cmdsub(void) { token saved = tok; @@ -930,7 +930,7 @@ static void lex_token(void) { while ((c = pgetc()) != '\n' && c != PEOF) ; } - tok.word = NULL; + tok.word = nullptr; tok.kw = KW_NONE; switch (c) { case PEOF: @@ -1185,7 +1185,7 @@ static void read_heredoc_body(heredoc *h) { */ static void read_heredocs(void) { heredoc *h = here_head; - here_head = NULL; + here_head = nullptr; here_tail = &here_head; for (; h; h = h->next) read_heredoc_body(h); @@ -1457,10 +1457,10 @@ static node *parse_case(void) { * Inside `[[ ]]` only an unquoted word can be an operator: `[[ "-f" ]]` * tests the string `-f`. * - * @return The text, or NULL. + * @return The text, or nullptr. */ static const char *cond_bare(void) { - return tok.t == T_WORD && tok.bare ? tok.word->parts->u.lit.s : NULL; + return tok.t == T_WORD && tok.bare ? tok.word->parts->u.lit.s : nullptr; } /** @@ -1486,7 +1486,7 @@ static char cond_unary_op(const char *s) { /** * @brief Is `s` a binary operator of `[[ ]]`? - * @param s Candidate text, or NULL. + * @param s Candidate text, or nullptr. * @param op Receives the operator. */ static bool cond_binary_op(const char *s, cond_op *op) { @@ -1712,7 +1712,7 @@ static node *parse_function_kw(void) { * @brief Give back text read while testing for `(( ))`, as a subshell. * @param sb What was read after the "((". * @param last The character read after that, or PEOF. - * @return NULL, for the caller to return. + * @return nullptr, for the caller to return. */ static node *arith_fallback(strbuf *sb, int last) { strbuf back; @@ -1723,7 +1723,7 @@ static node *arith_fallback(strbuf *sb, int last) { sb_putc(&back, (char)last); size_t len = back.len; input_push_back(sb_cstr(&back), len); - return NULL; + return nullptr; } /** @@ -1746,7 +1746,7 @@ static node *arith_fallback(strbuf *sb, int last) { * parentheses or a very long body, so that deeply nested subshells do not * get rescanned at every level. * - * @return An N_ARITH node, or NULL if this is not arithmetic. + * @return An N_ARITH node, or nullptr if this is not arithmetic. */ static node *parse_arith_command(void) { const size_t max_body = 4096; @@ -1835,7 +1835,7 @@ static node *parse_command_node(void) { if (tok.t == T_LP) { consume(); int c = pgetc(); - if (c == '(' && (n = parse_arith_command()) != NULL) { + if (c == '(' && (n = parse_arith_command()) != nullptr) { parse_redirs(n); return n; } @@ -2009,7 +2009,7 @@ static node *parse_list_item(tok_kind *term) { * on. */ static node *parse_clist(void) { - node *head = NULL; + node *head = nullptr; node **slot = &head; skip_newlines(); while (command_start() || peek_kw(KW_BANG)) { @@ -2027,11 +2027,11 @@ static node *parse_clist(void) { * * @param a Arena for the tree. * @param eof Set when the input has ended. - * @return The command, or NULL for an empty line. + * @return The command, or nullptr for an empty line. */ node *parse_command(arena *a, bool *eof) { pa = a; - node *head = NULL; + node *head = nullptr; node **slot = &head; for (;;) { tok_kind t = peek(); @@ -2128,7 +2128,7 @@ void parser_save(void *state) { parser_state *ps = state; *ps = (parser_state){pa, tok, tok_pushed, here_head, here_tail}; if (here_tail == &here_head) - ps->here_tail = NULL; + ps->here_tail = nullptr; parser_reset(); } diff --git a/src/parser.h b/src/parser.h index e2853d8..7926e9d 100644 --- a/src/parser.h +++ b/src/parser.h @@ -78,7 +78,7 @@ static inline int pgetc(void) { } /* - * Parse one complete command line into `a`. Returns NULL for a blank line; + * Parse one complete command line into `a`. Returns nullptr for a blank line; * sets *eof when the input is exhausted. */ node *parse_command(arena *a, bool *eof); diff --git a/src/pattern.c b/src/pattern.c index b54bf49..a60f643 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -18,7 +18,7 @@ * @return The index, or -1 if `c` is not in it. */ static int index_in(const char *set, unsigned char c) { - const char *p = c ? strchr(set, c) : NULL; + const char *p = c ? strchr(set, c) : nullptr; return p ? (int)(p - set) : -1; } @@ -129,8 +129,8 @@ static int match_bracket(const char *p, const char **endp, unsigned char c) { * @return true if all of [s, send) matches. */ bool pat_match(const char *pat, const char *s, const char *send) { - const char *star_pat = NULL; - const char *star_s = NULL; + const char *star_pat = nullptr; + const char *star_s = nullptr; for (;;) { char c = *pat; if (c == '*') { @@ -244,7 +244,7 @@ static void glob_from(globber *g, const char *pat) { if (dir) { char *comp = arena_strndup(&scratch, pat, clen); const struct dirent *de; - while ((de = readdir(dir)) != NULL) { + while ((de = readdir(dir)) != nullptr) { const char *name = de->d_name; if (name[0] == '.' && comp[0] != '.' && !(comp[0] == '\\' && comp[1] == '.')) diff --git a/src/printf.c b/src/printf.c index a7e60fa..3e33c53 100644 --- a/src/printf.c +++ b/src/printf.c @@ -99,7 +99,7 @@ typedef struct printf_state { * @brief Take the next argument, or an empty string when they have run out. */ static const char *next_arg(printf_state *pf) { - return *pf->args ? *pf->args++ : NULL; + return *pf->args ? *pf->args++ : nullptr; } /** @@ -171,7 +171,7 @@ static const char *copy_number(printf_state *pf, const char *f, char *spec, * @brief Handle one conversion. * @param pf printf state. * @param f Points just after the `%`. - * @return Position of the conversion character, or NULL to stop (an + * @return Position of the conversion character, or nullptr to stop (an * error, or `\c` in a `%b` argument). */ static const char *convert(printf_state *pf, const char *f) { @@ -243,13 +243,13 @@ static const char *convert(printf_state *pf, const char *f) { out_printf(&out1, spec, mem.buf); free(mem.buf); if (!more) - return NULL; + return nullptr; break; } default: sh_warn("printf: %%%c: invalid directive", *f ? *f : ' '); pf->status = 1; - return NULL; + return nullptr; } return f; } diff --git a/src/redir.c b/src/redir.c index 824394b..f49e818 100644 --- a/src/redir.c +++ b/src/redir.c @@ -381,7 +381,7 @@ void plan_init(fdplan *p, int in, int out) { p->map[0] = in; if (out >= 0) p->map[1] = out; - p->temps = NULL; + p->temps = nullptr; p->ntemps = 0; } diff --git a/src/shell.h b/src/shell.h index afd00ca..6a92a02 100644 --- a/src/shell.h +++ b/src/shell.h @@ -155,7 +155,7 @@ void sb_puts(strbuf *b, const char *s); */ static inline void sb_init(strbuf *b, arena *a) { b->a = a; - b->s = NULL; + b->s = nullptr; b->len = b->cap = 0; } @@ -31,7 +31,7 @@ typedef struct spawn_req { const int *fdmap; /** Bit i set: parent descriptor i is open (for identity entries). */ unsigned open_mask; - /** Signals to reset to default in the child, or NULL. */ + /** Signals to reset to default in the child, or nullptr. */ const sigset_t *sigdfl; /** Process group for the child: -1 to inherit the shell's, 0 to start * a new group, otherwise the group to join. (Job control.) */ diff --git a/src/sys_posix.c b/src/sys_posix.c index ba171b0..92f2d42 100644 --- a/src/sys_posix.c +++ b/src/sys_posix.c @@ -156,8 +156,8 @@ pid_t sys_spawn(const spawn_req *rq) { } posix_spawnattr_setflags(&attr, flags); } - rc = posix_spawn(&pid, rq->path, need_fa ? &fa : NULL, - need_attr ? &attr : NULL, rq->argv, rq->envp); + rc = posix_spawn(&pid, rq->path, need_fa ? &fa : nullptr, + need_attr ? &attr : nullptr, rq->argv, rq->envp); if (need_fa) posix_spawn_file_actions_destroy(&fa); if (need_attr) @@ -285,11 +285,11 @@ int sys_tag_set(const char *path, const char *codeset, int text) { /** * @brief System facts. None of the z/OS ones exist here. - * @return NULL: the ZOS_* variables are not defined on this platform. + * @return nullptr: the ZOS_* variables are not defined on this platform. */ const char *sys_info(sys_info_kind kind) { (void)kind; - return NULL; + return nullptr; } /* @@ -455,11 +455,11 @@ static int stub_iggcsi00(csi_area *a, void *ctx) { /** * @brief Open the test catalog. - * @return The file, or NULL if there is none. + * @return The file, or nullptr if there is none. */ static FILE *test_catalog(void) { const char *path = getenv("ZASH_TEST_CATALOG"); - return path ? fopen(path, "r") : NULL; + return path ? fopen(path, "r") : nullptr; } /** @@ -467,7 +467,7 @@ static FILE *test_catalog(void) { * @return true if a test catalog is named. */ bool sys_has_catalog(void) { - return getenv("ZASH_TEST_CATALOG") != NULL; + return getenv("ZASH_TEST_CATALOG") != nullptr; } /** @brief Work area size for the stand-in: small, to force resumes. */ diff --git a/src/sys_zos.c b/src/sys_zos.c index f6fc862..38908ce 100644 --- a/src/sys_zos.c +++ b/src/sys_zos.c @@ -473,7 +473,7 @@ int sys_tag_get(const char *path, sys_tag *tag) { /** * @brief Change a file's tag. * @param path The file. - * @param codeset A code set name or CCSID number. NULL removes the tag; + * @param codeset A code set name or CCSID number. nullptr removes the tag; * "BINARY" tags the file as binary. * @param text 1 text, 0 not text, -1 keep the current flag. * @return 0, or -1 with errno set (EINVAL for an unknown code set). @@ -597,7 +597,7 @@ const char *sys_info(sys_info_kind kind) { * IBM recommends 64000; 32K already holds more names than a completion * screen shows, and it is taken per search rather than held. */ -#define CSI_WORK 32768 +constexpr unsigned CSI_WORK = 32768; /**< work area for one IGGCSI00 search */ /** @brief One search's storage: taken per search, freed before return. */ typedef struct csi_req { @@ -609,7 +609,7 @@ typedef struct csi_req { typedef int iggcsi_fn(void *reason, void *field, void *work); #pragma linkage(iggcsi_fn, OS) -static iggcsi_fn *csi_ep; /**< from fetch(), NULL until loaded */ +static iggcsi_fn *csi_ep; /**< from fetch(), nullptr until loaded */ static bool csi_dead; /**< fetch failed or a call abended */ static bool csi_in_flight; /**< one search at a time */ @@ -649,7 +649,7 @@ static int csi_call(csi_area *a, void *ctx) { rc = CSI_ABENDED; } for (int i = 0; i < NSIG_CSI; i++) - sigaction(sigs[i], &old[i], NULL); + sigaction(sigs[i], &old[i], nullptr); return rc; } @@ -691,7 +691,7 @@ bool sys_catalog_list(const char *filter, mvs_name_fn *fn, void *arg) { free(r); if (abended) { (void)release((void (*)(void))csi_ep); - csi_ep = NULL; + csi_ep = nullptr; csi_dead = true; ok = false; } @@ -743,7 +743,7 @@ bool sys_pds_members(const char *dsn, mvs_name_fn *fn, void *arg) { */ bool sys_dd_names(mvs_name_fn *fn, void *arg) { const unsigned char *tcb = ptr31(0x21c); - const unsigned char *tiot = tcb ? ptr31((uintptr_t)(tcb + 0xc)) : NULL; + const unsigned char *tiot = tcb ? ptr31((uintptr_t)(tcb + 0xc)) : nullptr; if (!tiot) return false; return tiot_parse(tiot + 24, TIOT_MAX, fn, arg); @@ -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])) diff --git a/src/unparse.c b/src/unparse.c index d775128..6a4e9cd 100644 --- a/src/unparse.c +++ b/src/unparse.c @@ -27,7 +27,7 @@ static void put_node(strbuf *sb, const node *n); static void put_lit(strbuf *sb, const char *s, size_t len, bool quoted) { bool need = quoted && !len; for (size_t i = 0; i < len && quoted && !need; i++) - need = strchr(" \t\n;&|<>()$`\\\"'*?[#~=%", s[i]) != NULL; + need = strchr(" \t\n;&|<>()$`\\\"'*?[#~=%", s[i]) != nullptr; if (!need) { sb_put(sb, s, len); return; @@ -76,7 +76,7 @@ static void put_param(strbuf *sb, const param *pm) { /** * @brief Append the parts of one word. * @param sb Destination. - * @param p First part, or NULL. + * @param p First part, or nullptr. * @param raw The parts are an arithmetic expression: literal text is * written as is (it was never shell-quoted). */ @@ -114,7 +114,7 @@ static void put_parts(strbuf *sb, const wpart *p, bool raw) { /** * @brief Append a list of words separated by spaces. * @param sb Destination. - * @param w First word, or NULL. + * @param w First word, or nullptr. * @param first Whether nothing precedes the list on this command (no * leading space is wanted then). * @return false if anything was written, else `first` unchanged. @@ -135,7 +135,7 @@ static bool put_words(strbuf *sb, const word *w, bool first) { /** * @brief Append a command's redirections. * @param sb Destination. - * @param r First redirection, or NULL. + * @param r First redirection, or nullptr. */ static void put_redirs(strbuf *sb, const redir *r) { static const char *const ops[] = { @@ -163,7 +163,7 @@ static void put_redirs(strbuf *sb, const redir *r) { /** * @brief Append a command list that sits inside a compound command. * @param sb Destination. - * @param n The list, or NULL for an empty one. + * @param n The list, or nullptr for an empty one. */ static void put_body(strbuf *sb, const node *n) { if (n) @@ -220,7 +220,7 @@ static void put_cond(strbuf *sb, const cond *c) { /** * @brief Append the text of one command. * @param sb Destination. - * @param n The command. Must not be NULL. + * @param n The command. Must not be nullptr. */ static void put_node(strbuf *sb, const node *n) { switch (n->kind) { @@ -338,7 +338,7 @@ static void put_node(strbuf *sb, const node *n) { /** * @brief Rebuild the text of a command. - * @param n The command, or NULL. + * @param n The command, or nullptr. * @return Heap-allocated text. The caller frees it. */ char *node_text(const node *n) { @@ -31,7 +31,7 @@ } /** - * @brief Allocate memory. Never returns NULL. + * @brief Allocate memory. Never returns nullptr. * @param n Bytes wanted (0 is treated as 1). * @return The block. The shell exits if memory is exhausted. */ @@ -43,8 +43,8 @@ void *xmalloc(size_t n) { } /** - * @brief Resize a heap block. Never returns NULL. - * @param p Block from xmalloc(), or NULL. + * @brief Resize a heap block. Never returns nullptr. + * @param p Block from xmalloc(), or nullptr. * @param n New size in bytes. * @return The resized block. The shell exits if memory is exhausted. */ @@ -155,7 +155,7 @@ static void arena_add_chunk(arena *a, size_t need) { arena_chunk *c; if (need <= size && a->spare) { c = a->spare; - a->spare = NULL; + a->spare = nullptr; } else { if (size < need) size = need; @@ -196,7 +196,7 @@ void *arena_alloc(arena *a, size_t n) { * block is allocated and the old contents copied. * * @param a The arena. - * @param p Existing block, or NULL. + * @param p Existing block, or nullptr. * @param oldn Its size. * @param newn Size wanted. * @return The block, possibly moved. @@ -245,7 +245,7 @@ void arena_release(arena *a, arena_marker m) { arena_drop_chunk(a, c); } a->next = m.next; - a->end = a->head ? a->head->end : NULL; + a->end = a->head ? a->head->end : nullptr; } /** @@ -285,7 +285,7 @@ void arena_reset(arena *a) { void arena_unref(arena *a) { if (--a->refs > 0) return; - arena_release(a, (arena_marker){NULL, NULL}); + arena_release(a, (arena_marker){nullptr, nullptr}); free(a->spare); free(a); } @@ -311,12 +311,12 @@ void sb_reserve(strbuf *b, size_t extra) { /** * @brief Append bytes to a string builder. * @param b The builder. - * @param s Bytes to append. May be NULL when `n` is 0. + * @param s Bytes to append. May be nullptr when `n` is 0. * @param n How many. */ void sb_put(strbuf *b, const char *s, size_t n) { if (!n) - return; /* `s` may be null: memcpy(p, NULL, 0) is undefined */ + return; /* `s` may be null: memcpy(p, nullptr, 0) is undefined */ sb_reserve(b, n); memcpy(b->s + b->len, s, n); b->len += n; @@ -51,7 +51,7 @@ static size_t env_cap; static bool env_dirty = true; /** - * @brief The innermost active scope, or NULL. + * @brief The innermost active scope, or nullptr. */ varscope *var_scope; /** @@ -109,7 +109,7 @@ static char *make_text(const char *name, size_t nlen, const char *value) { * @param name Name (not NUL-terminated). * @param nlen Its length. * @param create Make an unset variable if there is none. - * @return The variable, or NULL. + * @return The variable, or nullptr. */ var *var_find(const char *name, size_t nlen, bool create) { for (var *v = vtab[hash_name(name, nlen)]; v; v = v->next) { @@ -117,7 +117,7 @@ var *var_find(const char *name, size_t nlen, bool create) { return v; } if (!create) - return NULL; + return nullptr; return var_link(make_text(name, nlen, ""), nlen, V_UNSET); } @@ -125,12 +125,12 @@ var *var_find(const char *name, size_t nlen, bool create) { * @brief Value of a variable. * @param name Name (not NUL-terminated). * @param nlen Its length. - * @return The value, or NULL if the variable is unset. + * @return The value, or nullptr if the variable is unset. */ const char *var_get_n(const char *name, size_t nlen) { const var *v = var_find(name, nlen, false); if (!v || (v->flags & V_UNSET)) - return NULL; + return nullptr; if (v->flags & V_DYNAMIC) return v->get(); return v->text + nlen + 1; @@ -151,7 +151,7 @@ static void var_changed(var *v, unsigned old_flags) { if ((v->flags | old_flags) & V_EXPORT) env_dirty = true; if (v->hook) - v->hook((v->flags & V_UNSET) ? NULL : v->text + v->nlen + 1); + v->hook((v->flags & V_UNSET) ? nullptr : v->text + v->nlen + 1); } /** @@ -311,7 +311,7 @@ void var_each(void (*fn)(const char *name, void *arg), void *arg) { */ void scope_push(varscope *s, bool capture, bool is_func) { s->prev = var_scope; - s->saved = NULL; + s->saved = nullptr; s->depth = var_scope ? var_scope->depth + 1 : 1; s->capture = capture; s->func = is_func; @@ -386,7 +386,7 @@ char **var_environ(void) { } if (!env_cache) env_cache = xmalloc(sizeof *env_cache); - env_cache[n] = NULL; + env_cache[n] = nullptr; env_dirty = false; return env_cache; } @@ -415,7 +415,7 @@ char **var_environ_with(char **extra, int nextra) { if (!shadowed) env[k++] = base[i]; } - env[k] = NULL; + env[k] = nullptr; return env; } @@ -509,7 +509,7 @@ static bool random_seeded; static const char *get_random(void) { static char buf[INT_BUFSZ]; if (!random_seeded) { - random_state = (unsigned)time(NULL) ^ ((unsigned)getpid() << 8); + random_state = (unsigned)time(nullptr) ^ ((unsigned)getpid() << 8); random_seeded = true; } random_state = random_state * 1103515245u + 12345u; @@ -518,7 +518,7 @@ static const char *get_random(void) { /** @brief Assignment to `RANDOM` seeds the generator. */ static void set_random(const char *value) { - random_state = (unsigned)strtoul(value, NULL, 10); + random_state = (unsigned)strtoul(value, nullptr, 10); random_seeded = true; } @@ -530,12 +530,12 @@ static time_t seconds_base; /** @brief Value of `$SECONDS`. */ static const char *get_seconds(void) { static char buf[INT_BUFSZ]; - return fmt_int((intmax_t)(time(NULL) - seconds_base), buf); + return fmt_int((intmax_t)(time(nullptr) - seconds_base), buf); } /** @brief Assignment to `SECONDS` restarts the count from that value. */ static void set_seconds(const char *value) { - seconds_base = time(NULL) - (time_t)strtol(value, NULL, 10); + seconds_base = time(nullptr) - (time_t)strtol(value, nullptr, 10); } /** @@ -574,11 +574,11 @@ static void tag_err_changed(const char *v) { static void watch(const char *name, void (*hook)(const char *value)) { var *v = var_find(name, strlen(name), true); v->hook = hook; - hook((v->flags & V_UNSET) ? NULL : v->text + v->nlen + 1); + hook((v->flags & V_UNSET) ? nullptr : v->text + v->nlen + 1); } /** - * @brief A system fact for a ZOS_* variable. Never NULL (a dynamic + * @brief A system fact for a ZOS_* variable. Never nullptr (a dynamic * variable's getter must return a string). */ static const char *zos_info(sys_info_kind kind) { @@ -665,7 +665,7 @@ void var_init(char **envp) { v = var_link(ifs, 3, V_NOFREE); } v->hook = ifs_changed; - ifs_changed(NULL); + ifs_changed(nullptr); set_default(ps1); set_default(ps2); @@ -674,7 +674,7 @@ void var_init(char **envp) { set_dynamic(lineno, get_lineno); set_dynamic(ppid, get_ppid); /* Computed when read, so they cost nothing until a script asks. */ - seconds_base = time(NULL); + seconds_base = time(nullptr); set_dynamic(random, get_random); var_find("RANDOM", 6, false)->set = set_random; set_dynamic(seconds, get_seconds); @@ -704,7 +704,7 @@ void var_init(char **envp) { */ void params_free(shparam *sp) { free(sp->base); - sp->base = NULL; + sp->base = nullptr; } /** @@ -722,7 +722,7 @@ void params_set(char **argv, int n) { p[i] = memcpy(s, argv[i], len); s += len; } - p[n] = NULL; + p[n] = nullptr; params_free(&shellparam); shellparam = (shparam){n, p, p}; } @@ -102,7 +102,7 @@ extern char ifs_first; /**< separator for "$*"; '\0' if IFS is empty */ typedef struct shparam { int n; char **p; - void *base; /**< heap block holding p and the strings, or NULL */ + void *base; /**< heap block holding p and the strings, or nullptr */ } shparam; extern shparam shellparam; |
