1 #include <dirent.h>
2 #include <stdbool.h>
3 #include <sys/types.h>
4 
5 
6 #ifndef FS
7 #define FS
8 struct path
9 	{
10 	char *p, *e, *z;
11 	};
12 
plen(struct path x)13 static inline size_t plen(struct path x)
14 	{
15 	return x.z - x.p;
16 	}
17 
dlen(struct path x)18 static inline size_t dlen(struct path x)
19 	{
20 	return x.e - x.p;
21 	}
22 
elen(struct path x)23 static inline size_t elen(struct path x)
24 	{
25 	return x.z - x.e;
26 	}
27 
is_dot(const char * e)28 static inline bool is_dot(const char *e)
29 	{
30 	return e[0] == '.' && (!e[1] || (e[1] == '.' && !e[2]));
31 	}
32 
33 enum type { Unknown, None, Dir, Other };
34 #endif
35 
36 
37 struct path build_path(const char *p);
38 enum type file_type(bool follow, const char *p);
39 DIR *open_dir(const char *p);
40 void pretty_print(const char *p, enum type typ);
41 bool rm_rf(const char *p);
42 int safe_rename(const char *src, enum type typ, const char *dst);
43