openMSX
FileOperations.hh
Go to the documentation of this file.
1 #ifndef FILEOPERATIONS_HH
2 #define FILEOPERATIONS_HH
3 
4 #include "string_ref.hh"
5 #include "unistdp.hh" // needed for mode_t definition when building with VC++
6 #include "statp.hh"
7 #include <sys/types.h>
8 #include <fstream>
9 
10 namespace openmsx {
11 namespace FileOperations {
12 
13  const char nativePathSeparator =
14 #ifdef _WIN32
15  '\\';
16 #else
17  '/';
18 #endif
19 
25  std::string expandTilde(string_ref path);
26 
38  void mkdir(const std::string& path, mode_t mode);
39 
46  void mkdirp(string_ref path);
47 
51  int unlink(const std::string& path);
52 
56  int rmdir(const std::string& path);
57 
61  int deleteRecursive(const std::string& path);
62 
69  FILE* openFile(const std::string& filename, const std::string& mode);
70 
76  void openofstream(std::ofstream& stream, const std::string& filename);
77 
84  void openofstream(std::ofstream& stream, const std::string& filename,
85  std::ios_base::openmode mode);
86 
93 
102 
111 
120 
127  std::string join(string_ref part1, string_ref part2);
128  std::string join(string_ref part1, string_ref part2, string_ref part3);
129  std::string join(string_ref part1, string_ref part2,
130  string_ref part3, string_ref part4);
131 
139  std::string getConventionalPath(string_ref path);
140 
148  std::string getNativePath(string_ref path);
149 
153  std::string getCurrentWorkingDirectory();
154 
158  std::string getAbsolutePath(string_ref path);
159 
164  bool isAbsolutePath(string_ref path);
165 
177  std::string getUserHomeDir(string_ref username);
178 
183  const std::string& getUserOpenMSXDir();
184 
189  std::string getUserDataDir();
190 
196  std::string getSystemDataDir();
197 
202  std::string expandCurrentDirFromDrive(string_ref path);
203 
204 #ifdef _WIN32
205  typedef struct _stat Stat;
206 #else
207  typedef struct stat Stat;
208 #endif
209 
215  bool getStat(const std::string& filename, Stat& st);
216 
220  bool isRegularFile(const std::string& filename);
221  bool isRegularFile(const Stat& st);
222 
226  bool isDirectory(const std::string& directory);
227  bool isDirectory(const Stat& st);
228 
232  bool exists(const std::string& filename);
233 
236  time_t getModificationDate(const Stat& st);
237 
247  std::string getNextNumberedFileName(
248  string_ref directory, string_ref prefix, string_ref extension);
249 
258  std::string parseCommandFileArgument(
259  string_ref argument, string_ref directory,
260  string_ref prefix, string_ref extension);
261 
266  std::string getTempDir();
267 
274  FILE* openUniqueFile(const std::string& directory, std::string& filename);
275 
276 } // namespace FileOperations
277 } // namespace openmsx
278 
279 #endif