mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
pwd: correctly handle write errors
This commit is contained in:
parent
cfc95994de
commit
ffaf2582a3
1 changed files with 11 additions and 2 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue