From ffaf2582a342df8aa6226fc72eabd8e18155d078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 8 Apr 2025 16:18:57 +0200 Subject: [PATCH] pwd: correctly handle write errors --- src/executing/simple_cmd/builtin_pwd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/executing/simple_cmd/builtin_pwd.c b/src/executing/simple_cmd/builtin_pwd.c index 29aabde..fdd043d 100644 --- a/src/executing/simple_cmd/builtin_pwd.c +++ b/src/executing/simple_cmd/builtin_pwd.c @@ -6,7 +6,7 @@ /* 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 "../../ft_errno.h" #include "errno.h" +#include static char *get_current_dir(void) { @@ -37,6 +38,13 @@ static char *get_current_dir(void) 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) { char *path; @@ -50,7 +58,8 @@ t_builtin_type builtin_pwd(t_simple_cmd *cmd, t_minishell *app) } else { - ft_printf("%s\n", path); + if (ft_printf("%s\n", path) < 0) + return (free(path), write_error(app)); free(path); app->last_return_value = 0; }