-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcd.c
33 lines (30 loc) · 1.32 KB
/
cd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kristori <kristori@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 11:45:22 by kristori #+# #+# */
/* Updated: 2023/04/04 14:47:09 by kristori ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_cd(t_prompt *prompt)
{
char *buf;
char *path;
if (chdir(((t_mini *)prompt->cmds->content)->full_cmd[1]) != 0)
return ;
if (ft_strcmp(((t_mini *)prompt->cmds->content)->full_cmd[1], "..") != 0)
{
buf = (char *)malloc(100 * sizeof(char));
getcwd(buf, 100);
path = ft_strjoin(buf, "/");
path = ft_strjoin2(path,
((t_mini *)prompt->cmds->content)->full_cmd[1]);
chdir(path);
free(buf);
free(path);
}
}