malloc_safe

- add freelist to minishell
- add t_minishell *minishell to all function calling malloc_free
- substituted all malloc calls but the first to malloc_safe
This commit is contained in:
whaffman 2025-02-25 14:54:17 +01:00
parent 1d4316cbf1
commit ab72bd5bbb
49 changed files with 289 additions and 278 deletions

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:26:35 by whaffman #+# #+# */
/* Updated: 2025/02/11 15:39:15 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:31:55 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -15,13 +15,14 @@
# include "minishell.h"
void environment_add(t_list **environment, char *name, char *value);
void environment_print(t_list *environment);
t_environment *environment_get(t_list *environment, char *name);
void environment_free_list(t_list **environment);
int environment_parse(char **envp, t_list **environment);
char **environment_get_arr(t_list *environment);
void environment_del(t_list **environment, char *name);
void environment_add(t_minishell *minishell,
char *name, char *value);
void environment_print(t_minishell *minishell);
t_environment *environment_get(t_minishell *minishell, char *name);
void environment_free_list(t_minishell *minishell);
int environment_parse(t_minishell *minishell, char **envp);
char **environment_get_arr(t_minishell *minishell);
void environment_del(t_minishell *minishell, char *name);
void environment_free(void *content);
#endif // ENVIRONMENT_H

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/08 17:06:07 by willem #+# #+# */
/* Updated: 2025/02/21 13:16:29 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:52:05 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -15,9 +15,9 @@
# include "minishell.h"
char *executor_absolute_path(t_list *env, char *cmd);
void executor_child(t_command *command);
pid_t executor_fork(t_command *command);
char *executor_absolute_path(t_minishell *minishell, char *cmd);
void executor_child(t_minishell *minishell, t_command *command);
pid_t executor_fork(t_minishell *minishell, t_command *command);
void executor_create_pipes(t_minishell *minishell);
int executor_execute_pipeline(t_minishell *minishell);
void executor_close_fds(int n_fds);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/18 19:00:51 by qmennen #+# #+# */
/* Updated: 2025/02/21 16:13:32 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:32:18 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -19,7 +19,10 @@ t_environment *expander_get_var(const char *s, int idx,
t_minishell *minishell);
t_list *expander_parse_variables(const char *s,
t_minishell *minishell);
char *expander_allocate_memory(const char *s, t_list *variables);
char *expander_allocate_memory(
t_minishell *minishell,
const char *s,
t_list *variables);
char *expander_parse_string(char *s, t_minishell *minishell);
int expander_character_valid(const char c);
int expander_expand_dollar(char *src, char *dest,

View File

@ -15,7 +15,7 @@
# include "minishell.h"
t_command *parser_command_new(char *cmd);
t_command *parser_command_new(t_minishell *minishell, char *cmd);
char **parser_get_arguments(t_list *list, t_minishell *minishell);
t_list *parser_get_commands(t_minishell *minishell);
t_list *parser_get_input_redirects(t_list *list);

View File

@ -14,9 +14,9 @@
# define REDIRECT_H
# include "minishell.h"
t_redirect *redirect_new(t_token_type type, char *value);
t_list *redirect_get_inputs(t_list *list);
t_list *redirect_get_outputs(t_list *list);
t_redirect *redirect_new(t_minishell *minishell, t_token_type type, char *value);
t_list *redirect_get_inputs(t_minishell *minishell, t_list *list);
t_list *redirect_get_outputs(t_minishell *minishell, t_list *list);
int redirect_is_valid(t_list *lst, t_token *token);
int redirect_token_type(t_token *token);
int redirect_is_delimiter(t_token *token);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokenizer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 12:36:00 by whaffman #+# #+# */
/* Updated: 2025/02/18 17:02:17 by qmennen ### ########.fr */
/* :::::::: */
/* tokenizer.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 12:36:00 by whaffman #+# #+# */
/* Updated: 2025/02/25 14:45:15 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -16,18 +16,18 @@
/**
* Lexer
*/
t_lexer *ft_lexer_new(const char *input);
t_lexer *ft_lexer_new(t_minishell *minishell);
void ft_lexer_free(t_lexer *lexer);
void lexer_readchar(t_lexer *lexer);
char *lexer_readword(t_lexer *lexer);
t_list *ft_parse_input(t_lexer *lexer);
char *lexer_readword(t_minishell *minishell, t_lexer *lexer);
t_list *ft_parse_input(t_minishell *minishell);
/**
* Token
*/
t_token *ft_token_next(t_lexer *lexer);
t_token *token_new(t_token_type type, char *c, int pos);
t_token *ft_token_next(t_minishell *minishell, t_lexer *lexer);
t_token *token_new(t_minishell *minishell, t_token_type type, char *c, int pos);
void ft_token_free(t_token *token);
void ft_clear_tokenlist(void *content);
t_token *token_parse(t_lexer *lexer);
t_token *token_parse(t_minishell *minishell, t_lexer *lexer);
#endif // TOKENIZER_H

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* typedef.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */
/* Updated: 2025/02/20 16:45:55 by qmennen ### ########.fr */
/* :::::::: */
/* typedef.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */
/* Updated: 2025/02/25 13:23:12 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -78,6 +78,7 @@ typedef struct s_minishell
t_lexer *lexer;
t_list *tokens;
t_list *commands;
t_list *freelist;
} t_minishell;
typedef int (*t_builtin_fn)(t_minishell *, t_command *);

View File

@ -21,9 +21,9 @@ void print_banner(void);
void print_list(void *content);
void simple_builtins(t_minishell *minishell);
void error_msg(char *func, char *msg);
void check_malloc(void *ptr);
char *ft_strdup_safe(const char *str);
char *ft_strjoin_safe(const char *s1, const char *s2);
void *ft_malloc_safe(size_t size);
void check_malloc(t_minishell *minishell, void *ptr);
char *ft_strdup_safe(t_minishell *minishell, const char *str);
char *ft_strjoin_safe(t_minishell *minishell, const char *s1, const char *s2);
void *malloc_safe(t_minishell *minishell, size_t size);
#endif // UTILS_H

View File

@ -1,20 +1,22 @@
VPATH = src:src/parser:src/environment:src/lexer:src/debug:src/token:src/signal:src/prompt:src/utils:src/expander:src/executor:src/builtin:
SOURCES = parser_get_arguments.c parser_new_command.c parser_get_commands.c \
environment_get.c environment_get_arr.c environment_free_list.c \
environment_add.c environment_print.c environment_del.c \
environment_free.c environment_parse.c lexer_new.c lexer_read_word.c \
lexer_read_char.c lexer_parse_input.c lexer_token_next.c \
print_commands.c main.c token_new.c token_parse.c signal.c \
history_write.c prompt.c history_load.c ft_malloc_safe.c \
free_command_list.c free_minishell.c free_lexer.c print_banner.c \
check_malloc.c error_msg.c free_token_list.c free_minishell_line.c \
ft_strdup_safe.c free_token.c init_minishell.c ft_strjoin_safe.c \
expander_allocate_memory.c expander_parse_string.c \
expander_parse_variables.c expander_expand_dollar.c \
expander_is_character.c expander_get_variable.c executor_open_fds.c \
executor_count_fds.c executor_fork.c executor_absolute_path.c \
executor_execute_pipeline.c executor_child.c executor_close_fds.c \
executor_create_redirects.c executor_create_pipes.c builtin_export.c \
simple_builtins.c builtin_router.c is_builtin.c builtin_unset.c \
builtin_env.c builtin_cd.c builtin_pwd.c builtin_exit.c \
builtin_echo.c \
VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/signal:src/debug:src/expander:src/builtin:src/redirect:
SOURCES = history_load.c history_write.c prompt.c free_lexer.c free_token.c \
free_token_list.c free_minishell.c free_minishell_line.c \
init_minishell.c check_malloc.c error_msg.c free_command_list.c \
ft_malloc_safe.c ft_strdup_safe.c ft_strjoin_safe.c print_banner.c \
free_freelist.c lexer_read_char.c lexer_token_next.c \
lexer_parse_input.c lexer_new.c lexer_read_word.c token_new.c \
token_parse.c environment_free.c environment_del.c \
environment_free_list.c environment_get.c environment_parse.c \
environment_add.c environment_get_arr.c environment_print.c \
executor_close_fds.c executor_child.c executor_fork.c \
executor_absolute_path.c executor_execute_pipeline.c \
executor_count_fds.c executor_create_redirects.c executor_open_fds.c \
executor_create_pipes.c parser_get_arguments.c parser_new_command.c \
parser_get_commands.c signal.c print_commands.c \
expander_expand_dollar.c expander_get_variable.c \
expander_is_character.c expander_parse_variables.c \
expander_parse_string.c expander_allocate_memory.c builtin_cd.c \
builtin_echo.c builtin_env.c builtin_export.c builtin_pwd.c \
builtin_router.c builtin_unset.c simple_builtins.c builtin_exit.c \
is_builtin.c main.c redirect_get_inputs.c redirect_get_outputs.c \
redirect_new.c redirect_valid_type.c \

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 11:33:07 by whaffman #+# #+# */
/* Updated: 2025/02/20 12:49:36 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:57:57 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@ int builtin_cd(t_minishell *minishell, t_command *cmd)
if (cmd->args[1] == NULL)
{
env = environment_get(minishell->environment, "HOME");
env = environment_get(minishell, "HOME");
if (env == NULL || env->value == NULL)
{
ft_putendl_fd("minishell: cd: HOME not set", STDERR_FILENO);

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 11:33:02 by whaffman #+# #+# */
/* Updated: 2025/02/20 12:17:10 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:57:49 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -15,6 +15,6 @@
int builtin_env(t_minishell *minishell, t_command *cmd)
{
(void)cmd;
environment_print(minishell->environment);
environment_print(minishell);
return (SUCCESS);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 11:32:53 by whaffman #+# #+# */
/* Updated: 2025/02/20 12:30:21 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:57:08 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -28,14 +28,14 @@ int builtin_export(t_minishell *minishell, t_command *cmd)
i++;
continue ;
}
env = environment_get(minishell->environment, arr[0]);
env = environment_get(minishell, arr[0]);
if (env != NULL)
{
free(env->value);
env->value = ft_strdup(arr[1]); //TODO: malloc check
}
else
environment_add(&(minishell->environment), arr[0], arr[1]);
environment_add(minishell, arr[0], arr[1]);
ft_free_arr(arr);
i++;
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 11:25:43 by whaffman #+# #+# */
/* Updated: 2025/02/20 15:04:59 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:57:29 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -19,8 +19,8 @@ int builtin_unset(t_minishell *minishell, t_command *cmd)
i = 1;
while (cmd->args[i] != NULL)
{
if (environment_get(minishell->environment, cmd->args[i]) != NULL)
environment_del(&(minishell->environment), cmd->args[i]);
if (environment_get(minishell, cmd->args[i]) != NULL)
environment_del(minishell, cmd->args[i]);
i++;
}
return (SUCCESS);

View File

@ -6,20 +6,22 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:33 by whaffman #+# #+# */
/* Updated: 2025/02/12 21:33:20 by willem ######## odam.nl */
/* Updated: 2025/02/25 14:28:43 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void environment_add(t_list **environment, char *name, char *value)
void environment_add(t_minishell *minishell, char *name, char *value)
{
t_environment *new_environment;
t_list *new_node;
t_list **environment;
environment = &minishell->environment;
if (name != NULL && value != NULL)
{
new_environment = malloc(sizeof(t_environment));
new_environment = malloc_safe(minishell, sizeof(t_environment));
if (new_environment == NULL)
return (perror("malloc"));
new_environment->name = ft_strdup(name);

View File

@ -6,13 +6,13 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 14:17:53 by whaffman #+# #+# */
/* Updated: 2025/02/11 17:20:26 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:41:06 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void environment_del(t_list **environment, char *name)
void environment_del(t_minishell *minishell, char *name)
{
t_list *prev;
t_list *current;
@ -21,7 +21,7 @@ void environment_del(t_list **environment, char *name)
prev = NULL;
next = NULL;
current = *environment;
current = minishell->environment;
while (current != NULL)
{
env = (t_environment *)current->content;
@ -31,7 +31,7 @@ void environment_del(t_list **environment, char *name)
environment_free(current->content);
free(current);
if (prev == NULL)
*environment = next;
minishell->environment = next;
else
prev->next = next;
return ;

View File

@ -6,13 +6,13 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:59 by whaffman #+# #+# */
/* Updated: 2025/02/11 17:18:27 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:37:21 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void environment_free_list(t_list **environment)
void environment_free_list(t_minishell *minishell)
{
ft_lstclear(environment, environment_free);
ft_lstclear(&(minishell->environment), environment_free);
}

View File

@ -6,16 +6,18 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:15:05 by whaffman #+# #+# */
/* Updated: 2025/02/11 17:04:28 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:35:13 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_environment *environment_get(t_list *environment, char *name)
t_environment *environment_get(t_minishell *minishell, char *name)
{
t_environment *env;
t_list *environment;
environment = minishell->environment;
while (environment != NULL)
{
env = (t_environment *)environment->content;

View File

@ -6,28 +6,26 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/08 13:59:48 by willem #+# #+# */
/* Updated: 2025/02/11 17:18:15 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:29:49 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char **environment_get_arr(t_list *environment)
char **environment_get_arr(t_minishell *minishell)
{
char **arr;
t_environment *env;
int i;
t_list *environment;
arr = malloc(sizeof(char *) * (ft_lstsize(environment) + 1));
if (arr == NULL)
return (NULL);
environment = minishell->environment;
arr = malloc_safe(minishell, sizeof(char *) * (ft_lstsize(environment) + 1));
i = 0;
while (environment != NULL)
{
env = (t_environment *)environment->content;
arr[i] = malloc(ft_strlen(env->name) + ft_strlen(env->value) + 2);
if (arr[i] == NULL)
return (ft_free_arr(arr), NULL);
arr[i] = malloc_safe(minishell, ft_strlen(env->name) + ft_strlen(env->value) + 2);
ft_strlcpy(arr[i], env->name, ft_strlen(env->name) + 1);
ft_strlcat(arr[i], "=", ft_strlen(env->name) + 2);
ft_strlcat(arr[i], env->value,

View File

@ -6,23 +6,23 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 15:52:33 by whaffman #+# #+# */
/* Updated: 2025/02/11 17:18:43 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:42:22 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
int environment_parse(char **envp, t_list **environment)
int environment_parse(t_minishell *minishell, char **envp)
{
char **env;
*environment = NULL;
if (envp == NULL)
return (FAILURE);
while (*envp != NULL)
{
env = ft_split(*envp, '=');
environment_add(environment, env[0], env[1]);
environment_add(minishell, env[0], env[1]);
ft_free_arr(env);
envp++;
}

View File

@ -6,23 +6,18 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/08 13:52:08 by willem #+# #+# */
/* Updated: 2025/02/11 17:05:10 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:39:45 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void environment_print(t_list *environment)
void environment_print(t_minishell *minishell)
{
char **arr;
int i;
arr = environment_get_arr(environment);
if (arr == NULL)
{
perror("malloc");
return ;
}
arr = environment_get_arr(minishell);
i = 0;
while (arr[i] != NULL)
{

View File

@ -6,13 +6,13 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/08 17:00:24 by willem #+# #+# */
/* Updated: 2025/02/13 15:04:09 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:30:18 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *executor_absolute_path(t_list *env, char *cmd)
char *executor_absolute_path(t_minishell *minishell, char *cmd)
{
char **path;
t_environment *path_env;
@ -30,16 +30,14 @@ char *executor_absolute_path(t_list *env, char *cmd)
}
return (NULL);
}
path_env = environment_get(env, "PATH");
path_env = environment_get(minishell, "PATH");
if (!path_env)
return (NULL);
path = ft_split(path_env->value, ':');
i = 0;
while (path[i] != NULL)
{
executable = malloc(ft_strlen(path[i]) + ft_strlen(cmd) + 2);
if (!executable)
return (ft_free_arr(path), NULL);
executable = malloc_safe(minishell, ft_strlen(path[i]) + ft_strlen(cmd) + 2);
ft_strlcpy(executable, path[i], ft_strlen(path[i]) + 1);
ft_strlcat(executable, "/", ft_strlen(path[i]) + 2);
ft_strlcat(executable, cmd, ft_strlen(path[i]) + ft_strlen(cmd) + 2);

View File

@ -6,21 +6,22 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:25:10 by willem #+# #+# */
/* Updated: 2025/02/19 12:56:03 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:52:53 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void executor_child(t_command *command)
void executor_child(t_minishell *minishell, t_command *command)
{
char *path;
if (command->fd_in != 0)
dup2(command->fd_in, 0);
if (command->fd_out != 1)
dup2(command->fd_out, 1);
executor_close_fds(command->n_fds);
path = executor_absolute_path(command->environment, command->command);
path = executor_absolute_path(minishell, command->command);
if (path == NULL)
{
ft_putstr_fd(RED BOLD, 2);
@ -28,5 +29,5 @@ void executor_child(t_command *command)
ft_putstr_fd(": " RESET "command not found\n", 2);
return ;
}
execve(path, command->args, environment_get_arr(command->environment));
execve(path, command->args, environment_get_arr(minishell));
}

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:25:22 by willem #+# #+# */
/* Updated: 2025/02/22 22:25:28 by willem ######## odam.nl */
/* Updated: 2025/02/25 14:19:57 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -38,7 +38,7 @@ void executor_create_pipes(t_minishell *minishell)
command = (t_command *)current->content;
if (current->next)
{
if (!pipe(fd))
if (pipe(fd) == -1)
error_msg("pipe", "pipe creation failed");
command->fd_out = fd[1];
}

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
/* Updated: 2025/02/21 13:11:17 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:52:35 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -27,7 +27,7 @@ int executor_execute_pipeline(t_minishell *minishell)
{
command = (t_command *)current->content;
command->environment = minishell->environment;
last_pid = executor_fork(command);
last_pid = executor_fork(minishell, command);
current = current->next;
}
waitpid(last_pid, &exit_status, 0);

View File

@ -6,13 +6,13 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:24:52 by willem #+# #+# */
/* Updated: 2025/02/19 13:40:19 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:51:48 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
pid_t executor_fork(t_command *command)
pid_t executor_fork(t_minishell *minishell, t_command *command)
{
pid_t pid;
// int status;
@ -31,7 +31,7 @@ pid_t executor_fork(t_command *command)
else if (pid == 0)
{
signal_init_child();
executor_child(command);
executor_child(minishell, command);
exit(127);
}
else

View File

@ -1,18 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expander_allocate_memory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 13:57:19 by qmennen #+# #+# */
/* Updated: 2025/02/19 13:57:36 by qmennen ### ########.fr */
/* :::::::: */
/* expander_allocate_memory.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/19 13:57:19 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:31:33 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *expander_allocate_memory(const char *s, t_list *variables)
char *expander_allocate_memory(
t_minishell *minishell,
const char *s,
t_list *variables)
{
int size;
t_list *current;
@ -26,14 +29,14 @@ char *expander_allocate_memory(const char *s, t_list *variables)
if (current->content == NULL)
{
current = current->next;
continue;
continue ;
}
env = (t_environment *)current->content;
size += (ft_strlen(env->value) - ft_strlen(env->name));
current = current->next;
}
size += ft_strlen(s);
string = malloc(size);
string = malloc_safe(minishell, size);
if (!string)
perror("expander malloc");
return (string);

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expander_get_variable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/19 13:59:03 by qmennen #+# #+# */
/* Updated: 2025/02/19 13:59:14 by qmennen ### ########.fr */
/* :::::::: */
/* expander_get_variable.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/19 13:59:03 by qmennen #+# #+# */
/* Updated: 2025/02/25 13:47:55 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -24,7 +24,7 @@ t_environment *expander_get_var(const char *s, int idx, t_minishell *minishell)
name = ft_substr(s, idx, i);
if (!name || !*name)
return (NULL);
env = environment_get(minishell->environment, name);
env = environment_get(minishell, name);
free(name);
return (env);
}

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expander_parse_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/18 19:00:35 by qmennen #+# #+# */
/* Updated: 2025/02/20 16:38:28 by qmennen ### ########.fr */
/* :::::::: */
/* expander_parse_string.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/18 19:00:35 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:32:59 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -35,7 +35,7 @@ char *expander_parse_string(char *s, t_minishell *minishell)
int j;
variables = expander_parse_variables(s, minishell);
string = expander_allocate_memory(s, variables);
string = expander_allocate_memory(minishell, s, variables);
i = 0;
j = 0;
current = variables;

View File

@ -1,27 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 19:03:01 by qmennen #+# #+# */
/* Updated: 2025/02/05 19:08:41 by qmennen ### ########.fr */
/* :::::::: */
/* lexer_new.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 19:03:01 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:35:35 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_lexer *ft_lexer_new(const char *input)
t_lexer *ft_lexer_new(t_minishell *minishell)
{
t_lexer *lexer;
char *input;
lexer = malloc(sizeof(t_lexer));
if (!lexer)
{
perror("failed assigning lexer memory");
exit(EXIT_FAILURE);
}
t_lexer *lexer;
input = minishell->line;
lexer = malloc_safe(minishell, sizeof(t_lexer));
lexer->input = ft_strdup(input);
lexer->pos = 0;
lexer->n_pos = 1;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_parse_input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 19:09:20 by qmennen #+# #+# */
/* Updated: 2025/02/20 16:42:39 by qmennen ### ########.fr */
/* :::::::: */
/* lexer_parse_input.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 19:09:20 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:39:37 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -23,16 +23,18 @@
* the input to be parsed.
* @return A linked list of tokens parsed from the input.
*/
t_list *ft_parse_input(t_lexer *lexer)
t_list *ft_parse_input(t_minishell *minishell)
{
t_list *list;
t_token *token;
t_lexer *lexer;
lexer = minishell->lexer;
list = NULL;
while (TRUE)
{
//TODO: Check if unicode support is viable
token = ft_token_next(lexer);
token = ft_token_next(minishell, lexer);
if (token->type == T_EOF || token->type == T_ERROR) //TODO T_ERROR removes the inf loop
break ;
ft_lstadd_back(&list, ft_lstnew(token));

View File

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_read_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 19:03:47 by qmennen #+# #+# */
/* Updated: 2025/02/19 14:12:19 by qmennen ### ########.fr */
/* :::::::: */
/* lexer_read_word.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 19:03:47 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:40:33 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
static char *parse_quotes(t_lexer *lexer)
static char *parse_quotes(t_minishell *minishell, t_lexer *lexer)
{
int start;
int len;
@ -26,7 +26,7 @@ static char *parse_quotes(t_lexer *lexer)
while (lexer->current_char != '\0' && lexer->current_char != qc)
lexer_readchar(lexer);
len = lexer->pos - start;
word = malloc(sizeof(char) * len + 1);
word = malloc_safe(minishell, sizeof(char) * len + 1);
ft_strlcpy(word, lexer->input + start, len + 1);
if (lexer->current_char == qc)
lexer_readchar(lexer);
@ -38,7 +38,7 @@ static char *parse_quotes(t_lexer *lexer)
return (word);
}
char *lexer_readword(t_lexer *lexer)
char *lexer_readword(t_minishell *minishell, t_lexer *lexer)
{
int start;
int len;
@ -47,7 +47,7 @@ char *lexer_readword(t_lexer *lexer)
start = lexer->pos;
if (lexer->current_char == '"' || lexer->current_char == '\'')
{
return (parse_quotes(lexer));
return (parse_quotes(minishell, lexer));
}
while (ft_isprint(lexer->current_char) && lexer->current_char != '<'
&& lexer->current_char != '>' && lexer->current_char != '|'
@ -57,7 +57,7 @@ char *lexer_readword(t_lexer *lexer)
lexer_readchar(lexer);
}
len = lexer->pos - start;
word = malloc(sizeof(char) * len + 1);
word = malloc_safe(minishell, sizeof(char) * len + 1);
ft_strlcpy(word, lexer->input + start, len + 1);
return (word);
}

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:07:58 by qmennen #+# #+# */
/* Updated: 2025/02/20 10:39:50 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:45:28 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -42,7 +42,7 @@ static t_token_type get_word_type(char c)
* - If it is a printable character, reads the word and creates a word token.
* - Otherwise, creates an error token.
*/
t_token *ft_token_next(t_lexer *lexer)
t_token *ft_token_next(t_minishell *minishell, t_lexer *lexer)
{
t_token *token;
t_token_type word_type;
@ -54,22 +54,22 @@ t_token *ft_token_next(t_lexer *lexer)
lexer_readchar(lexer);
current_pos = lexer->pos;
if (lexer->current_char == '\0')
token = token_new(T_EOF, NULL, current_pos);
token = token_new(minishell, T_EOF, NULL, current_pos);
else if (lexer->current_char == '<' || lexer->current_char == '>'
|| lexer->current_char == '|')
token = token_parse(lexer);
token = token_parse(minishell, lexer);
else if (ft_isprint(lexer->current_char))
{
word_type = get_word_type(lexer->current_char);
word = lexer_readword(lexer);
word = lexer_readword(minishell, lexer);
if (!word)
return (token_new(T_ERROR, &lexer->current_char, current_pos));
token = token_new(word_type, word, current_pos);
return (token_new(minishell, T_ERROR, &lexer->current_char, current_pos));
token = token_new(minishell, word_type, word, current_pos);
free(word);
}
else
{
token = token_new(T_ERROR, NULL, current_pos);
token = token_new(minishell, T_ERROR, NULL, current_pos);
printf("token->type: %d\n", token->type);
}
return (token);

View File

@ -24,14 +24,14 @@ int main(int argc, char **argv, char **envp)
history_load();
minishell = init_minishell();
signal_init_minishell();
environment_parse(envp, &(minishell->environment));
environment_parse(minishell, envp);
while (TRUE)
{
minishell->line = ft_prompt(minishell);
if (minishell->line == NULL)
break ;
minishell->lexer = ft_lexer_new(minishell->line);
minishell->tokens = ft_parse_input(minishell->lexer);
minishell->lexer = ft_lexer_new(minishell);
minishell->tokens = ft_parse_input(minishell);
//ft_lstiter(minishell->tokens, token_print);
minishell->commands = parser_get_commands(minishell);
simple_builtins(minishell);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 16:20:09 by qmennen #+# #+# */
/* Updated: 2025/02/12 12:58:42 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:41:06 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -50,12 +50,7 @@ char **parser_get_arguments(t_list *list, t_minishell *minishell)
int i;
cmds = count_cmds(list);
args = malloc((cmds + 1) * sizeof(char *));
if (!args)
{
perror("malloc");
exit(EXIT_FAILURE);
}
args = malloc_safe(minishell, (cmds + 1) * sizeof(char *));
current = list;
i = -1;
while ((++i) < cmds && current)

View File

@ -31,10 +31,10 @@ t_list *parser_get_commands(t_minishell *minishell)
while (current)
{
token = (t_token *) current->content;
command = parser_command_new(ft_strdup(token->value));
command = parser_command_new(minishell, ft_strdup(token->value));
command->args = parser_get_arguments(current, minishell);
command->redirect_in = redirect_get_inputs(current);
command->redirect_out = redirect_get_outputs(current);
command->redirect_in = redirect_get_inputs(minishell, current);
command->redirect_out = redirect_get_outputs(minishell, current);
ft_lstadd_back(&command_list, ft_lstnew(command));
while (current && is_command_token((t_token *)current->content))
current = current->next;

View File

@ -6,22 +6,18 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
/* Updated: 2025/02/21 13:07:47 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:41:57 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_command *parser_command_new(char *cmd)
t_command *parser_command_new(t_minishell *minishell, char *cmd)
{
t_command *command;
command = malloc(sizeof(t_command));
if (!command)
{
perror("minishell malloc error");
exit(EXIT_FAILURE);
}
command = malloc_safe(minishell, sizeof(t_command));
\
command->args = NULL;
command->fd_in = 0;
command->fd_out = 1;

View File

@ -6,13 +6,13 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
/* Updated: 2025/02/19 13:44:20 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:43:34 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *get_user(t_list *environment)
char *get_user(t_minishell *minishell)
{
const char guest[] = "guest";
int len;
@ -20,37 +20,32 @@ char *get_user(t_list *environment)
char *username;
char *result;
user = environment_get(environment, "USER");
user = environment_get(minishell, "USER");
if (user == NULL)
username = (char *)guest;
else
username = user->value;
len = ft_strlen(username) + ft_strlen(PROMPT GREEN) + 1;
result = (char *)malloc(len);
if (result == NULL)
{
perror("malloc");
return (NULL);
}
result = (char *)malloc_safe(minishell, len);
ft_strlcpy(result, GREEN, ft_strlen(GREEN) + 1);
ft_strlcat(result, username, ft_strlen(GREEN) + ft_strlen(username) + 1);
ft_strlcat(result, PROMPT, len);
return (result);
}
int get_home_len(char *cwd, t_list *environment)
int get_home_len(t_minishell *minishell, char *cwd)
{
t_environment *home;
int home_len;
home = environment_get(environment, "HOME");
home = environment_get(minishell, "HOME");
home_len = 0;
if (home && !ft_strncmp(cwd, home->value, ft_strlen(home->value)))
home_len = ft_strlen(home->value) - 1;
return (home_len);
}
char *get_path_with_home(t_list *environment)
char *get_path_with_home(t_minishell *minishell)
{
char *result;
char *cwd;
@ -60,11 +55,9 @@ char *get_path_with_home(t_list *environment)
cwd = getcwd(NULL, 0);
if (cwd == NULL)
return (perror("getcwd"), NULL);
home_len = get_home_len(cwd, environment);
home_len = get_home_len(minishell, cwd);
len = ft_strlen(cwd) - home_len + 1;
result = malloc(len);
if (result == NULL)
return (free(cwd), NULL);
result = malloc_safe(minishell, len);
if (home_len)
{
ft_strlcpy(result, "~", 2);
@ -76,17 +69,17 @@ char *get_path_with_home(t_list *environment)
return (result);
}
char *get_path(t_list *environment)
char *get_path(t_minishell *minishell)
{
char *result;
char *cwd;
int len;
cwd = get_path_with_home(environment);
cwd = get_path_with_home(minishell);
if (cwd == NULL)
return (NULL);
len = ft_strlen(cwd) + ft_strlen(BLUE RESET "> ") + 1;
result = malloc(len);
result = malloc_safe(minishell, len);
if (result == NULL)
{
perror("malloc");
@ -106,10 +99,10 @@ char *ft_prompt(t_minishell *minishell)
char *prompt;
char *user;
cwd = get_path(minishell->environment);
cwd = get_path(minishell);
if (cwd == NULL)
return (NULL);
user = get_user(minishell->environment);
user = get_user(minishell);
if (user == NULL)
return (free(cwd), NULL);
prompt = ft_strjoin(user, cwd);

View File

@ -12,7 +12,7 @@
# include "redirect.h"
t_list *redirect_get_inputs(t_list *list)
t_list *redirect_get_inputs(t_minishell *minishell, t_list *list)
{
t_list *current;
t_list *redirects;
@ -32,13 +32,15 @@ t_list *redirect_get_inputs(t_list *list)
}
if (redirect_is_valid(current, token))
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(token->type, ft_strdup(((t_token *)current->next->content)->value))));
ft_lstadd_front(&redirects, ft_lstnew(
redirect_new(minishell, token->type,
ft_strdup(((t_token *)current->next->content)->value))));
current = current->next;
continue ;
}
else
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(T_ERROR, NULL)));
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(minishell, T_ERROR, NULL)));
break ;
}
current = current->next;

View File

@ -12,7 +12,7 @@
#include "minishell.h"
t_list *redirect_get_outputs(t_list *list)
t_list *redirect_get_outputs(t_minishell *minishell, t_list *list)
{
t_list *current;
t_list *redirects;
@ -32,13 +32,13 @@ t_list *redirect_get_outputs(t_list *list)
}
if (redirect_is_valid(current, token))
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(token->type, ft_strdup(((t_token *)current->next->content)->value))));
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(minishell, token->type, ft_strdup(((t_token *)current->next->content)->value))));
current = current->next;
continue ;
}
else
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(T_ERROR, NULL)));
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(minishell, T_ERROR, NULL)));
break ;
}
current = current->next;

View File

@ -12,11 +12,11 @@
#include "minishell.h"
t_redirect *redirect_new(t_token_type type, char *value)
t_redirect *redirect_new(t_minishell * minishell, t_token_type type, char *value)
{
t_redirect *result;
result = ft_malloc_safe(sizeof(t_redirect));
result = malloc_safe(minishell, sizeof(t_redirect));
result->type = type;
result->value = NULL;
if (value)

View File

@ -1,27 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* token_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 19:10:49 by qmennen #+# #+# */
/* Updated: 2025/02/18 17:01:52 by qmennen ### ########.fr */
/* :::::::: */
/* token_new.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 19:10:49 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:43:56 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_token *token_new(t_token_type type, char *c, int pos)
t_token *token_new(t_minishell *minishell, t_token_type type, char *c, int pos)
{
t_token *token;
token = malloc(sizeof(t_token));
if (!token)
{
perror("failed assigning token memory");
exit(EXIT_FAILURE);
}
token = malloc_safe(minishell, sizeof(t_token));
token->type = type;
token->position = pos;
if (c)

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* token_parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/05 19:10:17 by qmennen #+# #+# */
/* Updated: 2025/02/18 17:02:17 by qmennen ### ########.fr */
/* :::::::: */
/* token_parse.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 19:10:17 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:45:08 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -56,7 +56,7 @@ static char *char_from_type(t_token_type type)
return (NULL);
}
t_token *token_parse(t_lexer *lexer)
t_token *token_parse(t_minishell *minishell, t_lexer *lexer)
{
int is_double;
char c;
@ -66,7 +66,7 @@ t_token *token_parse(t_lexer *lexer)
c = lexer->current_char;
is_double = lexer->input[lexer->pos + 1] == c;
type = token_from_char(c, is_double);
token = token_new(type, char_from_type(type), lexer->pos);
token = token_new(minishell, type, char_from_type(type), lexer->pos);
if (is_double)
lexer_readchar(lexer);
lexer_readchar(lexer);

View File

@ -13,11 +13,17 @@
#include "minishell.h"
void check_malloc(void *ptr)
void check_malloc(t_minishell *minishell, void *ptr)
{
if (ptr == NULL)
{
error_msg("malloc", "can't allocate memory");
ft_lstclear(&(minishell->freelist), free);
exit(1);
}
else
{
ft_lstadd_front(&(minishell->freelist), ft_lstnew(ptr));
}
}

18
src/utils/free_freelist.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* free_freelist.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/25 13:23:30 by whaffman #+# #+# */
/* Updated: 2025/02/25 13:24:18 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void free_freelist(t_minishell *minishell)
{
ft_lstclear(&(minishell->freelist), free);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 16:03:57 by whaffman #+# #+# */
/* Updated: 2025/02/11 15:36:24 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 13:47:23 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -17,6 +17,6 @@ void free_minishell(t_minishell *minishell)
if (minishell->line)
free_minishell_line(minishell);
if (minishell->environment)
environment_free_list(&minishell->environment);
environment_free_list(minishell);
free(minishell);
}

View File

@ -12,11 +12,11 @@
#include "minishell.h"
void *ft_malloc_safe(size_t size)
void *malloc_safe(t_minishell *minishell, size_t size)
{
void *ptr;
ptr = malloc(size);
check_malloc(ptr);
check_malloc(minishell, ptr);
return (ptr);
}

View File

@ -12,11 +12,11 @@
#include "minishell.h"
char *ft_strdup_safe(const char *str)
char *ft_strdup_safe(t_minishell *minishell, const char *str)
{
char *new_str;
new_str = ft_strdup(str);
check_malloc(new_str);
check_malloc(minishell, new_str);
return (new_str);
}

View File

@ -12,12 +12,12 @@
#include "minishell.h"
char *ft_strjoin_safe(const char *s1, const char *s2)
char *ft_strjoin_safe(t_minishell *minishell, const char *s1, const char *s2)
{
char *new_str;
new_str = ft_strjoin(s1, s2);
check_malloc(new_str);
check_malloc(minishell, new_str);
return (new_str);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 16:03:03 by whaffman #+# #+# */
/* Updated: 2025/02/05 16:03:15 by whaffman ######## odam.nl */
/* Updated: 2025/02/25 14:50:19 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -27,5 +27,6 @@ t_minishell *init_minishell(void)
minishell->lexer = NULL;
minishell->tokens = NULL;
minishell->commands = NULL;
minishell->freelist = NULL;
return (minishell);
}