multiple fixes

This commit is contained in:
2026-02-14 13:48:15 +01:00
parent ba40670ace
commit 5852e8618f
7 changed files with 23 additions and 28 deletions

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/10 22:22:06 by sede-san #+# #+# */
/* Updated: 2026/02/12 02:55:36 by sede-san ### ########.fr */
/* Updated: 2026/02/14 06:58:05 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,3 +29,10 @@ void malloc_error(void)
{
ft_eprintf("minishell: %s\n", strerror(ENOMEM));
}
void command_not_found_error(
const char *command
)
{
ft_eprintf("minishell: %s: command not found\n", command);
}

View File

@@ -6,12 +6,13 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/11 00:00:00 by sede-san #+# #+# */
/* Updated: 2026/02/14 01:34:37 by sede-san ### ########.fr */
/* Updated: 2026/02/14 13:12:58 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
#include "executor.h"
#include "builtins.h"
#include "errors.h"
#include <errno.h>
static uint8_t resolve_execve_status(void)
@@ -60,10 +61,7 @@ static void execute_external_command(
envp = get_envp(minishell);
if (envp == NULL)
{
perror("get_envp");
exit(EXIT_FAILURE);
}
return (malloc_error(), exit(EXIT_FAILURE));
execve(command->path, command->argv, envp);
handle_execve_error(command, envp);
}
@@ -81,10 +79,7 @@ uint8_t executor_execute_command(
free(command->path);
command->path = executor_resolve_command_path(command, minishell);
if (command->path == NULL)
{
ft_eprintf("minishell: %s: command not found\n", command->argv[0]);
return (127);
}
return (command_not_found_error(command->argv[0]), 127);
execute_external_command(command, minishell);
return (EXIT_FAILURE);
}

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/08 19:10:47 by sede-san #+# #+# */
/* Updated: 2026/02/11 00:00:00 by sede-san ### ########.fr */
/* Updated: 2026/02/14 13:10:43 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/11 00:00:00 by sede-san #+# #+# */
/* Updated: 2026/02/14 01:17:01 by sede-san ### ########.fr */
/* Updated: 2026/02/14 13:16:15 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -38,7 +38,7 @@ static char *resolve_path_from_env(
return (NULL);
command_path = NULL;
i = -1;
while (!command_path && path_env[++i] != NULL)
while (command_name[0] != 0 && !command_path && path_env[++i] != NULL)
{
command_path = ft_strnjoin(3, path_env[i], "/", command_name);
if (command_path != NULL && access(command_path, X_OK) != EXIT_SUCCESS)

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/20 20:51:33 by sede-san #+# #+# */
/* Updated: 2026/02/14 02:23:17 by sede-san ### ########.fr */
/* Updated: 2026/02/14 12:57:00 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/13 21:09:23 by sede-san #+# #+# */
/* Updated: 2026/02/13 21:09:23 by sede-san ### ########.fr */
/* Updated: 2026/02/14 13:03:15 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,6 +31,7 @@ bool handle_eof(
return (false);
if (isatty(STDIN_FILENO))
ft_putendl("exit");
free(line);
minishell->exit = true;
return (true);
}

View File

@@ -6,7 +6,7 @@
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/01 09:12:39 by sede-san #+# #+# */
/* Updated: 2026/02/14 01:32:42 by sede-san ### ########.fr */
/* Updated: 2026/02/14 13:30:34 by sede-san ### ########.fr */
/* */
/* ************************************************************************** */
@@ -59,19 +59,13 @@ void set_env(
char *old_value;
environment = minishell->variables.environment;
key = (char *)name;
if (key != NULL && !ft_hashmap_contains_key(environment, key))
if (name != NULL && !ft_hashmap_contains_key(environment, name))
{
key = ft_strdup(name);
if (key == NULL)
{
minishell->exit = true;
malloc_error();
return ;
}
return (minishell->exit = true, malloc_error());
}
val = value;
if (val == NULL)
if (value == NULL)
val = ft_strdup("");
else
val = ft_strdup(value);
@@ -79,9 +73,7 @@ void set_env(
{
if (key != name)
free(key);
minishell->exit = true;
malloc_error();
return ;
return (minishell->exit = true, malloc_error());
}
old_value = ft_hashmap_put(environment, key, val);
if (old_value != NULL)