]> git.tdb.fi Git - libs/core.git/blob - source/utils.h
Get rid of the Path namespace
[libs/core.git] / source / utils.h
1 /* $Id$
2
3 This file is part of libmsppath
4 Copyright © 2006-2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_PATH_UTILS_H_
9 #define MSP_PATH_UTILS_H_
10
11 #include <sys/stat.h>
12 #include <list>
13 #include <string>
14
15 namespace Msp {
16
17 class Path;
18
19 struct Filename
20 {
21         std::string base;
22         std::string ext;
23 };
24
25 Path fix_case(const Path &path);
26
27 /// Creates a directory
28 void mkdir(const Path &path, int mode);
29
30 /// Creates a directory and any required parent directories
31 void mkpath(const Path &path, int mode);
32
33 /// Removes a directory
34 void rmdir(const Path &path);
35
36 /// Removes a directory and anything it contains
37 void rmdirs(const Path &path);
38
39 /// Removes a file
40 void unlink(const Path &path);
41
42 /// Lists the contents of a directory
43 std::list<std::string> list_files(const Path &path);
44
45 Filename splitext(const std::string &);
46 int fnmatch(const std::string &, const Path &);
47
48 /// Makes a path relative to some base path.  That is, base/result==path.
49 Path relative(const Path &path, const Path &base);
50
51 std::string basename(const std::string &);
52
53 /// Tests for existence of a file
54 bool exists(const Path &path);
55
56 /**
57 Gets information about a file.  Returns 0 on success or -1 on error.  This
58 version can be used to check for file existence and get information in one
59 call.
60 */
61 int stat(const Path &fn, struct stat &st);
62
63 /**
64 Returns information about a file.  This version throws an exception if an error
65 occurs.
66 */
67 struct stat stat(const Path &fn);
68
69 Path getcwd();
70
71 inline bool is_windows_drive(const std::string &p)
72 { return (p.size()==2 && ((p[0]>='A' && p[0]<='Z') || (p[0]>='a' && p[0]<='z')) && p[1]==':'); }
73
74 } // namespace Msp
75
76 #endif