Je ne comprends pas pourquoi ce message d'erreur s'affiche.
Sachant que dans ft_pwd, le seul appel à perror se fait si getcwd échoue, et que getcwd n'est normalement appelé qu'en tout dernier recours si ni l'environnement, ni le m->current_path ne sont remplis.
/*
1ère fonction : cherche dans l'env si PWD existe.
Si non, renvoie 0, pas de messages d'erreur : le reste du code se chargera de trouver le chemin à sa place.
*/
bool print_env_var(t_minishell *m, char *var)
{
t_envp_list *env;
size_t var_len;
env = m->list_envp;
var_len = ft_strlen(var);
while (env && env->next)
{
if (ft_strncmp(env->target, var, var_len) == 0)
{
ft_putendl_fd(env->value, 1);
return (1);
}
env = env->next;
}
return (0);
}
int ft_pwd(t_minishell *minishell)
{
char cwd[PATH_MAX];
if (print_env_var(minishell, "PWD="))
return (0);
if (minishell->current_path[0])
{
printf("%s\n", minishell->current_path);
return (0);
}
if (getcwd(cwd, sizeof(cwd)) == NULL)
{
perror("minishell: getcwd");
return (1);
}
printf("%s\n", cwd);
return (0);
}
MINISHELL
BASH
Je ne comprends pas pourquoi ce message d'erreur s'affiche. Sachant que dans ft_pwd, le seul appel à perror se fait si getcwd échoue, et que getcwd n'est normalement appelé qu'en tout dernier recours si ni l'environnement, ni le m->current_path ne sont remplis.