summaryrefslogtreecommitdiffhomepage
path: root/src/expand.c
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 00:30:44 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 00:30:44 -0600
commit5f92e02ff71be19067a422d324beb610cacd084d (patch)
tree1af510b0e4b9e3de95b18f476a6ebff2f109c488 /src/expand.c
parent7a7320b6a0d7dd6864b708b7e74fb5032a5bdf8e (diff)
downloadzash-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/expand.c')
-rw-r--r--src/expand.c24
1 files changed, 12 insertions, 12 deletions
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);
}
}