-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir_util.c
54 lines (48 loc) · 1.51 KB
/
dir_util.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dir_util.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asarandi <asarandi@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/03 18:41:19 by asarandi #+# #+# */
/* Updated: 2017/12/04 03:11:11 by asarandi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void directory_add_slash(char **path)
{
int len;
char *tmp;
len = ft_strlen(*path);
if ((*(*path)) && ((*path)[len - 1] != '/'))
{
tmp = ft_strjoin(*path, "/");
free((*path));
(*path) = tmp;
}
}
int is_directory(char *path, int show_error)
{
struct stat st;
int r;
r = lstat(path, &st);
if (r == 0)
{
if (S_ISDIR(st.st_mode))
return (1);
else
return (0);
}
if (show_error == 1)
ft_printf(2, "%s: %s: %s\n", g_ls_name, path, strerror(errno));
return (0);
}
int ok_to_recurse(char *path)
{
if (ft_strcmp(path, ".") == 0)
return (0);
if (ft_strcmp(path, "..") == 0)
return (0);
return (1);
}