42_minishell/builtins/cd.c
Etienne Rey-bethbeder 17ece4bc7b problème de
2023-02-21 14:49:42 +01:00

58 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
/* Updated: 2023/02/21 14:41:58 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int move_folder(char *path, int fd)
{
char *join;
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
{
if (chdir(path) == 0)
return (0);
ft_printf("chdir error");
return (1);
}
else
{
join = ft_strjoin("/", path);
join = ft_strfjoin(get_pwd(fd), join);
if (chdir(join) == 0)
{
free(join);
return (0);
}
free(join);
ft_printf("chdir error");
return (1);
}
}
/*int main(int argc, char *argv[]) {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("%s\n", cwd);
} else {
perror("getcwd() error");
return 1;
}
move_folder(argv[1], 1);
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("%s\n", cwd);
} else {
perror("getcwd() error");
return 1;
}
return 0;
}*/