mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
echo: correctly handle write errors such as /dev/full
This commit is contained in:
parent
871180f6d8
commit
cfc95994de
1 changed files with 19 additions and 4 deletions
|
|
@ -6,13 +6,14 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/03 13:59:13 by khais #+# #+# */
|
||||
/* Updated: 2025/04/03 17:18:54 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/14 11:52:37 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtins.h"
|
||||
#include "libft.h"
|
||||
#include "simple_cmd_execute.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static bool should_print_newline(t_wordlist **arg)
|
||||
{
|
||||
|
|
@ -42,6 +43,13 @@ static bool should_print_newline(t_wordlist **arg)
|
|||
return (print_newline);
|
||||
}
|
||||
|
||||
static t_builtin_type write_error(t_minishell *app)
|
||||
{
|
||||
app->last_return_value = 1;
|
||||
perror("minishell: echo: write error");
|
||||
return (BUILTIN_ECHO);
|
||||
}
|
||||
|
||||
t_builtin_type builtin_echo(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
t_wordlist *arg;
|
||||
|
|
@ -51,13 +59,20 @@ t_builtin_type builtin_echo(t_simple_cmd *cmd, t_minishell *app)
|
|||
print_newline = should_print_newline(&arg);
|
||||
while (arg != NULL)
|
||||
{
|
||||
ft_printf("%s", arg->word->word);
|
||||
if (ft_printf("%s", arg->word->word) < 0)
|
||||
return (write_error(app));
|
||||
arg = arg->next;
|
||||
if (arg != NULL)
|
||||
ft_printf(" ");
|
||||
{
|
||||
if (ft_printf(" ") < 0)
|
||||
return (write_error(app));
|
||||
}
|
||||
}
|
||||
if (print_newline)
|
||||
ft_printf("\n");
|
||||
{
|
||||
if (ft_printf("\n") < 0)
|
||||
return (write_error(app));
|
||||
}
|
||||
app->last_return_value = 0;
|
||||
return (BUILTIN_ECHO);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue