1 #ifndef MSP_FS_UTILS_H_
2 #define MSP_FS_UTILS_H_
9 /// Extracts the last component of the path.
10 std::string basename(const Path &);
12 /// Removes the last component from the path.
13 Path dirname(const Path &);
15 /** Returns the base part of a filename. This includes everything up to the
16 last dot, but not the dot itself. */
17 std::string basepart(const std::string &);
19 /** Returns the extension part of a filename. This includes the last dot and
20 everything after it. */
21 std::string extpart(const std::string &);
23 /// Fixes the case of a path to match files / directories on the filesystem.
24 Path fix_case(const Path &path);
26 /// Reads the contents of a symbolic link
27 Path readlink(const Path &path);
29 /// Resolves all symlinks from a path. Will always return an absolute path.
30 Path realpath(const Path &path);
33 void unlink(const Path &path);
35 /// Renames a file. Existing file, if any, is overwritten.
36 void rename(const Path &from, const Path &to);
38 /** Makes a path relative to some base path. That is, base/result==path. Both
39 paths must be either absolute or relative. */
40 Path relative(const Path &path, const Path &base);
42 /// Returns the longest prefix shared by both paths.
43 Path common_ancestor(const Path &, const Path &);
45 /** Determines how many levels a path is below another. Returns -1 if path is
46 not a descendant of parent. Both paths must be either absolute or relative. */
47 int descendant_depth(const Path &path, const Path &parent);