The builtins wasnt protected, now all data received is protected, the hashmap addition is protected and added functionality of env, export and unset (not implemented in this version). Added fixed details documentation in docs/builtins_fixes.md generated by codex and created tests/builtins_edge_cases.sh to test all the builtins to work correctly
62 lines
1.8 KiB
C
62 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* unset.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/02/09 22:05:00 by codex #+# #+# */
|
|
/* Updated: 2026/02/09 22:05:00 by codex ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "builtins.h"
|
|
|
|
static uint8_t is_valid_identifier(const char *arg);
|
|
static uint8_t unset_one(char *arg, t_minishell *msh);
|
|
|
|
uint8_t builtin_unset(
|
|
t_command cmd,
|
|
t_minishell *msh
|
|
)
|
|
{
|
|
uint8_t status;
|
|
size_t i;
|
|
|
|
status = EXIT_SUCCESS;
|
|
i = 0;
|
|
while (cmd.argv[++i] != NULL)
|
|
if (unset_one(cmd.argv[i], msh) != EXIT_SUCCESS)
|
|
status = EXIT_FAILURE;
|
|
return (status);
|
|
}
|
|
|
|
static uint8_t is_valid_identifier(
|
|
const char *arg
|
|
)
|
|
{
|
|
size_t i;
|
|
|
|
if (arg == NULL || *arg == '\0')
|
|
return (0);
|
|
if (!ft_isalpha(arg[0]) && arg[0] != '_')
|
|
return (0);
|
|
i = 0;
|
|
while (arg[++i] != '\0')
|
|
if (!ft_isalnum(arg[i]) && arg[i] != '_')
|
|
return (0);
|
|
return (1);
|
|
}
|
|
|
|
static uint8_t unset_one(
|
|
char *arg,
|
|
t_minishell *msh
|
|
)
|
|
{
|
|
if (!is_valid_identifier(arg))
|
|
return (ft_eprintf("minishell: unset: `%s': not a valid identifier\n",
|
|
arg), EXIT_FAILURE);
|
|
unset_env(arg, msh);
|
|
return (EXIT_SUCCESS);
|
|
}
|