-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_get_parent.c
More file actions
36 lines (33 loc) · 1.28 KB
/
ft_get_parent.c
File metadata and controls
36 lines (33 loc) · 1.28 KB
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
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_get_parent.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sid-bell <sid-bell@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/04 00:33:37 by sid-bell #+# #+# */
/* Updated: 2019/02/23 22:52:44 by sid-bell ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_get_parent_dir(char *dir)
{
char *pwd;
char *cdir;
int len;
char *parent;
pwd = ft_pwd();
if (!ft_strcmp(pwd, "/"))
return (pwd);
len = ft_strlen(dir);
if (dir[len - 1] == '/')
dir[len - 1] = '\0';
cdir = ft_strrchr(dir, '/');
len = len - ft_strlen(cdir);
if (len > 0)
parent = ft_strsub(dir, 0, len);
else
parent = ft_strdup("/");
free(pwd);
return (parent);
}