]> git.tdb.fi Git - libs/core.git/blob - source/fs/utils.h
Prepare for assimilation into core
[libs/core.git] / source / fs / utils.h
1 /* $Id$
2
3 This file is part of libmspfs
4 Copyright © 2006-2008  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_FS_UTILS_H_
9 #define MSP_FS_UTILS_H_
10
11 #include "path.h"
12
13 namespace Msp {
14 namespace FS {
15
16 /// Extracts the last component of the path.
17 std::string basename(const Path &);
18
19 /// Removes the last component from the path.
20 Path dirname(const Path &);
21
22 /**
23 Returns the base part of a filename.  This includes everything up to the last
24 dot, but not the dot itself.
25 */
26 std::string basepart(const std::string &);
27
28 /**
29 Returns the extension part of a filename.  This includes the last dot and
30 everything after it.
31 */
32 std::string extpart(const std::string &);
33
34 /**
35 Fixes the case of the given path to match files / directories on the
36 filesystem.
37 */
38 Path fix_case(const Path &path);
39
40 /// Reads the contents of a symbolic link
41 Path readlink(const Path &path);
42
43 /// Resolves all symlinks from a path.  Will always return an absolute path.
44 Path realpath(const Path &path);
45
46 /// Removes a file
47 void unlink(const Path &path);
48
49 /// Renames a file.  Existing file, if any, is overwritten.
50 void rename(const Path &from, const Path &to);
51
52 /// Makes a path relative to some base path.  That is, base/result==path.
53 Path relative(const Path &path, const Path &base);
54
55 /** Determines how many levels a path is below another.  Returns -1 if path is
56 not a descendant of parent. */
57 int descendant_depth(const Path &path, const Path &parent);
58
59 } // namespace FS
60 } // namespace Msp
61
62 #endif