mirror of
https://github.com/Savapitech/42sh.git
synced 2026-03-18 21:50:35 +01:00
Add unset env func
This commit is contained in:
14
src/env.c
14
src/env.c
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user