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/history.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/history.c')
| -rw-r--r-- | src/history.c | 26 |
1 files changed, 13 insertions, 13 deletions
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) |
