56 lines
1.6 KiB
C
56 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* cd.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
|
|
/* Updated: 2023/03/13 15:11:07 by erey-bet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "./builtins_private.h"
|
|
|
|
int make_move(char *path, int fd)
|
|
{
|
|
char *join;
|
|
|
|
join = ft_strjoin("/", path);
|
|
join = ft_strfjoin(get_pwd(fd), join);
|
|
if (chdir(join) == 0)
|
|
{
|
|
free(join);
|
|
return (0);
|
|
}
|
|
free(join);
|
|
write(2, "No such file or directory\n", 26);
|
|
return (1);
|
|
}
|
|
|
|
int move_folder(char **args, int fd)
|
|
{
|
|
char *path;
|
|
|
|
if (args[1] != NULL)
|
|
{
|
|
write(2, "cd: too many argument\n", 22);
|
|
return (1);
|
|
}
|
|
path = args[0];
|
|
if (!path)
|
|
{
|
|
write(2, "No such file or directory\n", 26);
|
|
return (1);
|
|
}
|
|
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
|
|
{
|
|
if (chdir(path) == 0)
|
|
return (0);
|
|
write(2, "No such file or directory\n", 26);
|
|
return (1);
|
|
}
|
|
else
|
|
return (make_move(path, fd));
|
|
}
|