Add unset env func

This commit is contained in:
savalet
2025-02-12 17:34:45 +01:00
parent 4078e4c688
commit f991d97d60
2 changed files with 16 additions and 0 deletions

View File

@@ -16,12 +16,14 @@
#include "u_mem.h"
#include "u_str.h"
__attribute__((nonnull))
void debug_env_entries(env_t *env)
{
for (size_t i = 0; i < env->sz; i++)
U_DEBUG("Env entry [%lu] [%s]\n", i, env->env[i]);
}
__attribute__((nonnull))
char *get_env_value(env_t *env, char const *key)
{
for (size_t i = 0; i < env->sz; i++)
@@ -30,6 +32,18 @@ char *get_env_value(env_t *env, char const *key)
return NULL;
}
__attribute__((nonnull))
bool unset_env(env_t *env, char *key)
{
for (size_t i = 0; i < env->sz; i++) {
if (u_strncmp(env->env[i], key, u_strlen(key)) == 0) {
env->env[i] = NULL;
return true;
}
}
return false;
}
static __attribute__((nonnull))
bool ensure_env_capacity(env_t *env)
{

View File

@@ -7,6 +7,7 @@
#ifndef ENV_H
#define ENV_H
#include <stdbool.h>
#include <stddef.h>
#define BASE_ENV_CAP 128
@@ -21,4 +22,5 @@ void debug_env_entries(env_t *env);
env_t parse_env(char **env);
char *get_env_value(env_t *env, char const *key);
bool unset_env(env_t *env, char *key);
#endif