diff options
Diffstat (limited to 'src/var.c')
| -rw-r--r-- | src/var.c | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -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}; } |
