cctools
path.h
1 /*
2  * Copyright (C) 2013- The University of Notre Dame
3  * This software is distributed under the GNU General Public License.
4  * See the file COPYING for details.
5  */
6 
7 #ifndef PATH_H
8 #define PATH_H
9 
10 #include "buffer.h"
11 
12 void path_absolute (const char *src, char *dest, int exist);
13 const char *path_basename (const char * path);
14 const char *path_extension (const char *path);
15 void path_collapse (const char *l, char *s, int remove_dotdot);
16 void path_dirname (const char *path, char *dir);
17 
25 int path_lookup (char *search_path, const char *exe, char *dest, size_t destlen);
26 
30 char *path_getcwd (void);
31 
32 void path_remove_trailing_slashes (char *path);
33 void path_split (const char *input, char *first, char *rest);
34 void path_split_multi (const char *input, char *first, char *rest);
35 
36 int path_find (buffer_t *B, const char *dir, const char *pattern, int recursive);
37 
38 int path_within_dir( const char *path, const char *dir );
39 
40 
41 /*
42 Returns the first absolute path for executable exec as found in PATH.
43 Returns NULL if none is found.
44 */
45 char *path_which(const char *exec);
46 
47 /* path_join_two_strings joins two strings, and adds sep between them.
48  * The caller should free the space pointed by the returned pointer.
49  */
50 char *path_join_two_strings(const char *s, const char *t, const char * sep);
51 
52 /* path_concat concatenates two file paths, with a slash as the separator.
53  * @param s: a file path
54  * @param t: a file path
55  * @return p: return the concatenated string on success, return NULL on failure.
56  * The caller should free the returned string.
57  */
58 char *path_concat(const char *s, const char *t);
59 
60 /* path_has_symlink checks whether any level of a path is symbolic link.
61  * return 0 if all the levels of the path are not symlink; otherwise return non-zero.
62  */
63 int path_has_symlink(const char *s);
64 
65 /* path_has_doubledots checks whether s includes double dots to reference a parent directory.
66  * if s looks like "a/../b", return 1; if s looks like "a/b..b/c", return 0.
67  */
68 int path_has_doubledots(const char *s);
69 
70 /* path_depth checks the depth of a path. The path should not include double dots.
71  * If s is an absolute path, return the depth of the path relative to /.
72  * If s is a relative path, return the depth of the path relative to CWD.
73  * return the depth of the path.
74  */
75 int path_depth(const char *s);
76 
81 int path_is_dir(char *file_name);
82 
83 
84 #endif
String Buffer Operations.
Definition: buffer.h:26