1#ifndef FILEOPERATIONS_HH
2#define FILEOPERATIONS_HH
20 using FILE_t = std::unique_ptr<FILE, FClose>;
34 [[nodiscard]] std::string
expandTilde(std::string path);
61 void mkdirp(std::string path);
100 std::ios_base::openmode mode);
107 [[nodiscard]] std::string_view
getFilename(std::string_view path);
116 [[nodiscard]] std::string_view
getDirName(std::string_view path);
125 [[nodiscard]] std::string_view
getExtension(std::string_view path);
134 [[nodiscard]] std::string_view
stripExtension(std::string_view path);
142 [[nodiscard]] std::string
join(std::string_view part1, std::string_view part2);
143 [[nodiscard]] std::string
join(std::string_view part1, std::string_view part2, std::string_view part3);
144 [[nodiscard]] std::string
join(std::string_view part1, std::string_view part2,
145 std::string_view part3, std::string_view part4);
171 [[nodiscard]]
inline const std::string&
getNativePath(
const std::string& path) {
return path; }
172 [[nodiscard]]
inline std::string
getNativePath( std::string&& path) {
return std::move(path); }
213 [[nodiscard]] std::string
getUserHomeDir(std::string_view username);
242 typedef struct _stat
Stat;
287 std::string_view directory, std::string_view prefix, std::string_view extension,
288 bool addSeparator =
false);
299 std::string_view argument, std::string_view directory,
300 std::string_view prefix, std::string_view extension);
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr time_t adjustTimeT(time_t time)
string parseCommandFileArgument(string_view argument, string_view directory, string_view prefix, string_view extension)
Helper function for parsing filename arguments in Tcl commands.
bool exists(zstring_view filename)
Does this file (directory) exists?
FILE_t openUniqueFile(const std::string &directory, std::string &filename)
Open a new file with a unique name in the provided directory.
void mkdir(zstring_view path, mode_t mode)
Create the specified directory.
string expandTilde(string path)
Expand the '~' character to the users home directory.
string_view getDirName(string_view path)
Returns the directory portion of a path.
string getNextNumberedFileName(string_view directory, string_view prefix, string_view extension, bool addSeparator)
Gets the next numbered file name with the specified prefix in the specified directory,...
const std::string & getNativePath(const std::string &path)
Returns the path in native path-delimiter.
string getCurrentWorkingDirectory()
Returns the current working directory.
const std::string & expandCurrentDirFromDrive(const std::string &path)
Get the current directory of the specified drive Linux: return the given string unchanged.
string getUserHomeDir(string_view username)
Get user's home directory.
bool isRegularFile(const Stat &st)
string_view getExtension(string_view path)
Returns the extension portion of a path.
const string & getUserOpenMSXDir()
Get the openMSX dir in the user's home directory.
int rmdir(zstring_view path)
Call rmdir() in a platform-independent manner.
string getAbsolutePath(string_view path)
Transform given path into an absolute path.
string_view stripExtension(string_view path)
Returns the path without extension.
string getTempDir()
Get the name of the temp directory on the system.
int deleteRecursive(const std::string &path)
bool isDirectory(const Stat &st)
void openOfStream(std::ofstream &stream, zstring_view filename)
Open an ofstream in a platform-independent manner.
bool isAbsolutePath(string_view path)
Checks whether it's a absolute path or not.
string_view getFilename(string_view path)
Returns the file portion of a path name.
const string & getSystemDataDir()
Get system directory.
std::optional< Stat > getStat(zstring_view filename)
Call stat() and return the stat structure.
FILE_t openFile(zstring_view filename, zstring_view mode)
Call fopen() in a platform-independent manner.
const string & getSystemDocDir()
Get system doc directory.
bool needsTildeExpansion(std::string_view path)
Returns true iff expandTilde(s) would have an effect.
const char nativePathSeparator
const std::string & getConventionalPath(const std::string &path)
Returns the path in conventional path-delimiter.
void mkdirp(string path)
Acts like the unix command "mkdir -p".
const string & getUserDataDir()
Get the openMSX data dir in the user's home directory.
std::unique_ptr< FILE, FClose > FILE_t
int unlink(zstring_view path)
Call unlink() in a platform-independent manner.
string join(string_view part1, string_view part2)
Join two paths.
time_t getModificationDate(const Stat &st)
Get the date/time of last modification.
void operator()(FILE *f) const