aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FileUtil.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/FileUtil.hh')
-rw-r--r--src/FbTk/FileUtil.hh94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/FbTk/FileUtil.hh b/src/FbTk/FileUtil.hh
new file mode 100644
index 0000000..718ccb8
--- /dev/null
+++ b/src/FbTk/FileUtil.hh
@@ -0,0 +1,94 @@
1// FileUtil.hh
2// Copyright (c) 2002 - 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id$
23
24#ifndef FBTK_FILEUTIL_HH
25#define FBTK_FILEUTIL_HH
26
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif // HAVE_CONFIG_H
30#ifdef HAVE_CTIME
31 #include <ctime>
32#else
33 #include <time.h>
34#endif
35#include <sys/types.h>
36#include <dirent.h>
37
38#include <string>
39
40#include "NotCopyable.hh"
41
42namespace FbTk {
43
44/// Wrapper for file routines
45
46namespace FileUtil {
47
48 /// @return true if file is a directory
49 bool isDirectory(const char* filename);
50 /// @return true if a file is a regular file
51 bool isRegularFile(const char* filename);
52 /// @return true if a file executable for user
53 bool isExecutable(const char* filename);
54
55 /// gets timestamp of last status change
56 /// @return timestamp
57 /// @return -1 (failure)
58 time_t getLastStatusChangeTimestamp(const char* filename);
59
60 /// copies file 'from' to 'to'
61 bool copyFile(const char* from, const char* to);
62
63}; // end of File namespace
64
65/// Wrapper class for DIR * routines
66class Directory : private FbTk::NotCopyable {
67public:
68 explicit Directory(const char *dir = 0);
69 ~Directory();
70 const std::string &name() const { return m_name; }
71 /// go to start of filelist
72 void rewind();
73 /// gets next dirent info struct in directory and
74 /// jumps to next directory entry
75 struct dirent * read();
76 /// reads next filename in directory
77 std::string readFilename();
78 /// close directory
79 void close();
80 /// open directory
81 /// @param dir the directory name
82 bool open(const char *dir);
83 /// @return number of entries in the directory
84 size_t entries() const { return m_num_entries; }
85
86private:
87 std::string m_name;
88 DIR *m_dir;
89 size_t m_num_entries; ///< number of file entries in directory
90};
91
92} // end namespace FbTk
93
94#endif // FBTK_FILEUTIL_HH