faboussard / 42_minishell

1 stars 0 forks source link

"pwd: ignoring non-option arguments" : je ne comprends pas d'ou vient cette erreur. #59

Closed melobern closed 4 months ago

melobern commented 5 months ago

MINISHELL

>>>  Minishell>$ pwd ls | wc
pwd: ignoring non-option arguments
      1       1      34

BASH

bash-5.2$ pwd ls | wc
      1       1      34

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);
}
melobern commented 4 months ago

Depuis les derniers changements, fonctionne normalement.