7 #ifndef _FCITX_UTILS_FS_H_ 8 #define _FCITX_UTILS_FS_H_ 10 #include <sys/types.h> 16 #include <string_view> 17 #include <fcitx-utils/fcitxutils_export.h> 18 #include <fcitx-utils/misc.h> 28 class StandardPathFile;
33 FCITXUTILS_EXPORT
bool isdir(
const std::string &path);
35 FCITXUTILS_EXPORT
bool isreg(
const std::string &path);
40 FCITXUTILS_EXPORT
bool isexe(
const std::string &path);
42 FCITXUTILS_EXPORT
bool islnk(
const std::string &path);
45 FCITXUTILS_EXPORT std::string
cleanPath(
const std::string &path);
47 FCITXUTILS_EXPORT
bool makePath(
const std::filesystem::path &path);
49 FCITXUTILS_EXPORT std::string
dirName(
const std::string &path);
51 FCITXUTILS_EXPORT std::string
baseName(std::string_view path);
54 FCITXUTILS_EXPORT ssize_t
safeRead(
int fd,
void *data,
size_t maxlen);
56 FCITXUTILS_EXPORT ssize_t
safeWrite(
int fd,
const void *data,
size_t maxlen);
58 FCITXUTILS_EXPORT std::optional<std::string>
readlink(
const std::string &path);
69 FCITXUTILS_EXPORT int64_t
modifiedTime(
const std::filesystem::path &path);
84 FCITXUTILS_EXPORT UniqueFilePtr
openFD(UnixFD &fd,
const char *modes);
95 FCITXUTILS_DEPRECATED_EXPORT UniqueFilePtr
openFD(StandardPathFile &file,
100 #endif // _FCITX_UTILS_FS_H_ std::string baseName(std::string_view path)
Get base file name of path.
bool islnk(const std::string &path)
check whether path is a link.
bool isexe(const std::string &path)
check whether path is an executable regular file.
bool isreg(const std::string &path)
check whether path is a regular file.
bool isdir(const std::string &path)
check whether path is a directory.
ssize_t safeWrite(int fd, const void *data, size_t maxlen)
a simple wrapper around write(), ignore EINTR.
std::string dirName(const std::string &path)
Get directory name of path.
std::optional< std::string > readlink(const std::string &path)
read symlink.
FCITXUTILS_DEPRECATED_EXPORT UniqueFilePtr openFD(StandardPathFile &file, const char *modes)
open the standard path file fd with fdopen.
bool makePath(const std::filesystem::path &path)
Create directory recursively.
int64_t modifiedTime(const std::filesystem::path &path)
Return modified time in seconds of given path.
ssize_t safeRead(int fd, void *data, size_t maxlen)
a simple wrapper around read(), ignore EINTR.
std::string cleanPath(const std::string &path)
Get the clean path by removing . , .. , and duplicate / in the path.