2023-02-21 08:45:43 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* cd.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
|
2023-03-09 14:13:38 -05:00
|
|
|
/* Updated: 2023/03/09 20:13:05 by erey-bet ### ########.fr */
|
2023-02-21 08:45:43 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-02-21 08:49:42 -05:00
|
|
|
#include "../minishell.h"
|
2023-02-21 08:45:43 -05:00
|
|
|
|
2023-03-09 14:13:38 -05:00
|
|
|
int make_move(char *path, int fd)
|
2023-02-21 08:45:43 -05:00
|
|
|
{
|
|
|
|
char *join;
|
2023-03-09 14:13:38 -05:00
|
|
|
|
|
|
|
join = ft_strjoin("/", path);
|
|
|
|
join = ft_strfjoin(get_pwd(fd), join);
|
|
|
|
if (chdir(join) == 0)
|
|
|
|
{
|
|
|
|
free(join);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
free(join);
|
|
|
|
write(2, "No suck file or directory", 25);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int move_folder(char **args, int fd)
|
|
|
|
{
|
2023-02-28 07:19:52 -05:00
|
|
|
char *path;
|
2023-02-21 08:45:43 -05:00
|
|
|
|
2023-02-28 07:19:52 -05:00
|
|
|
if (args[1] != NULL)
|
|
|
|
{
|
|
|
|
write(2, "cd: too many argument", 22);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
path = args[0];
|
2023-02-21 08:45:43 -05:00
|
|
|
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
|
|
|
|
{
|
|
|
|
if (chdir(path) == 0)
|
|
|
|
return (0);
|
2023-02-28 08:25:20 -05:00
|
|
|
write(2, "No suck file or directory", 25);
|
2023-02-21 08:45:43 -05:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
else
|
2023-03-09 14:13:38 -05:00
|
|
|
return (make_move(path, fd));
|
2023-02-21 08:45:43 -05:00
|
|
|
}
|