env: correctly handle write errors such as /dev/full

The exit status of 125 for env in case of failure is documented in env(1).
This commit is contained in:
Khaïs COLIN 2025-04-08 16:18:57 +02:00
parent ffaf2582a3
commit 0579d1f2fc
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,12 +6,20 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/02 19:35:52 by khais #+# #+# */
/* Updated: 2025/04/02 19:38:16 by khais ### ########.fr */
/* Updated: 2025/04/14 11:58:15 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "builtins.h"
#include "libft.h"
#include <stdio.h>
static t_builtin_type write_error(t_minishell *app)
{
app->last_return_value = 125;
perror("minishell: env: write error");
return (BUILTIN_ENV);
}
t_builtin_type builtin_env(t_simple_cmd *cmd, t_minishell *app)
{
@ -22,7 +30,8 @@ t_builtin_type builtin_env(t_simple_cmd *cmd, t_minishell *app)
env = app->env;
while (env != NULL)
{
ft_printf("%s=%s\n", env->key, env->value);
if (ft_printf("%s=%s\n", env->key, env->value) < 0)
return (write_error(app));
env = env->next;
}
app->last_return_value = 0;