pwd: correctly handle write errors

This commit is contained in:
Khaïs COLIN 2025-04-08 16:18:57 +02:00
parent cfc95994de
commit ffaf2582a3
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/31 14:21:52 by khais #+# #+# */ /* Created: 2025/03/31 14:21:52 by khais #+# #+# */
/* Updated: 2025/03/31 14:48:23 by khais ### ########.fr */ /* Updated: 2025/04/14 11:53:17 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,7 @@
#include "libft.h" #include "libft.h"
#include "../../ft_errno.h" #include "../../ft_errno.h"
#include "errno.h" #include "errno.h"
#include <stdio.h>
static char *get_current_dir(void) static char *get_current_dir(void)
{ {
@ -37,6 +38,13 @@ static char *get_current_dir(void)
return (path); return (path);
} }
static t_builtin_type write_error(t_minishell *app)
{
app->last_return_value = 1;
perror("minishell: pwd: write error");
return (BUILTIN_PWD);
}
t_builtin_type builtin_pwd(t_simple_cmd *cmd, t_minishell *app) t_builtin_type builtin_pwd(t_simple_cmd *cmd, t_minishell *app)
{ {
char *path; char *path;
@ -50,7 +58,8 @@ t_builtin_type builtin_pwd(t_simple_cmd *cmd, t_minishell *app)
} }
else else
{ {
ft_printf("%s\n", path); if (ft_printf("%s\n", path) < 0)
return (free(path), write_error(app));
free(path); free(path);
app->last_return_value = 0; app->last_return_value = 0;
} }