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
string getUserHomeDir(string_ref username)
Get user's home directory.
bool exists(const string &filename)
Does this file (directory) exists?
bool isAbsolutePath(string_ref path)
Checks whether it's a absolute path or not.
bool isRegularFile(const Stat &st)
int unlink(const std::string &path)
Call unlink() in a platform-independent manner.
void mkdirp(string_ref path_)
Acts like the unix command "mkdir -p".
string getNativePath(string_ref path)
Returns the path in native path-delimiter.
string getConventionalPath(string_ref path)
Returns the path in conventional path-delimiter.
void openofstream(std::ofstream &stream, const std::string &filename)
Open an ofstream in a platform-independent manner.
string getSystemDataDir()
Get system directory.
string getCurrentWorkingDirectory()
Returns the current working directory.
string join(string_ref part1, string_ref part2)
Join two paths.
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
string expandCurrentDirFromDrive(string_ref path)
Get the current directory of the specified drive Linux: just return an empty string.
string getAbsolutePath(string_ref path)
Transform given path into an absolute path.
bool getStat(const string &filename_, Stat &st)
Call stat() and return the stat structure.
string_ref getFilename(string_ref path)
Returns the file portion of a path name.
string parseCommandFileArgument(string_ref argument, string_ref directory, string_ref prefix, string_ref extension)
Helper function for parsing filename arguments in Tcl commands.
string getUserDataDir()
Get the openMSX data dir in the user's home directory.
FILE * openFile(const std::string &filename, const std::string &mode)
Call fopen() in a platform-independent manner.
string getNextNumberedFileName(string_ref directory, string_ref prefix, string_ref extension)
Gets the next numbered file name with the specified prefix in the specified directory, with the specified extension.
string_ref getBaseName(string_ref path)
Returns the directory portion of a path.
FILE * openUniqueFile(const std::string &directory, std::string &filename)
Open a new file with a unique name in the provided directory.
int rmdir(const std::string &path)
Call rmdir() in a platform-independent manner.
string_ref stripExtension(string_ref path)
Returns the path without extension.
const string & getUserOpenMSXDir()
Get the openMSX dir in the user's home directory.
void mkdir(const string &path, mode_t mode)
Create the specified directory.
bool isDirectory(const Stat &st)
string_ref getExtension(string_ref path)
Returns the extension portion of a path.
string getTempDir()
Get the name of the temp directory on the system.
string expandTilde(string_ref path)
Expand the '~' character to the users home directory.
int deleteRecursive(const std::string &path)
Recurively delete a file or directory and (in case of a directory) all its sub-components.
time_t getModificationDate(const Stat &st)
Get the date/time of last modification.