mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
feat(builtins/cd): on error, print path
This commit is contained in:
parent
29bbb5e572
commit
9fcb34e1d5
2 changed files with 21 additions and 6 deletions
|
|
@ -3,10 +3,10 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* builtin_cd.c :+: :+: :+: */
|
/* builtin_cd.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/31 16:20:17 by khais #+# #+# */
|
/* Created: 2025/03/31 16:20:17 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/07 17:35:16 by jguelen ### ########.fr */
|
/* Updated: 2025/04/25 16:07:25 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,10 +14,12 @@
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "../../env/env_manip.h"
|
#include "../../env/env_manip.h"
|
||||||
#include "../../ft_errno.h"
|
#include <errno.h>
|
||||||
|
|
||||||
static void ft_chdir(char *path, t_minishell *app)
|
static void ft_chdir(char *path, t_minishell *app)
|
||||||
{
|
{
|
||||||
|
int saveerrno;
|
||||||
|
|
||||||
if (path[0] == '\0')
|
if (path[0] == '\0')
|
||||||
app->last_return_value = 0;
|
app->last_return_value = 0;
|
||||||
else if (chdir(path) == 0)
|
else if (chdir(path) == 0)
|
||||||
|
|
@ -25,8 +27,9 @@ static void ft_chdir(char *path, t_minishell *app)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app->last_return_value = 1;
|
app->last_return_value = 1;
|
||||||
ft_errno(FT_EERRNO);
|
saveerrno = errno;
|
||||||
ft_perror("minishell: cd");
|
ft_dprintf(STDERR_FILENO, "minishell: cd: %s: %s\n", path,
|
||||||
|
strerror(saveerrno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
14
test.sh
14
test.sh
|
|
@ -243,11 +243,13 @@ when_run <<EOF "cd will print error when going into a directory with no access"
|
||||||
mkdir test
|
mkdir test
|
||||||
chmod -x test
|
chmod -x test
|
||||||
cd test
|
cd test
|
||||||
|
echo \$?
|
||||||
pwd
|
pwd
|
||||||
chmod +x test
|
chmod +x test
|
||||||
EOF
|
EOF
|
||||||
expecting <<EOF
|
expecting <<EOF
|
||||||
minishell: cd: Permission denied
|
minishell: cd: test: Permission denied
|
||||||
|
1
|
||||||
/tmp/dir.minishell
|
/tmp/dir.minishell
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -1225,4 +1227,14 @@ minishell: qwertyuiop: command not found
|
||||||
minishell: qwertyuiop: command not found
|
minishell: qwertyuiop: command not found
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "cd into a file"
|
||||||
|
touch file
|
||||||
|
cd file
|
||||||
|
echo \$?
|
||||||
|
EOF
|
||||||
|
expecting <<EOF
|
||||||
|
minishell: cd: file: Not a directory
|
||||||
|
1
|
||||||
|
EOF
|
||||||
|
|
||||||
finalize
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue