Fcitx
fs_deprecated.cpp
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #include <cstdint>
9 #include <cstdio>
10 #include <filesystem>
11 #include <string>
12 #include <string_view>
13 #include "fcitx-utils/fcitxutils_export.h"
14 #include "fs.h"
15 #include "misc.h"
16 #include "standardpath.h"
17 
18 namespace fcitx::fs {
19 
20 // FIXME: Remove this deprecated API in future releases.
21 FCITXUTILS_DEPRECATED_EXPORT bool makePath(const std::string &path) {
22  return makePath(std::filesystem::path(path));
23 }
24 
25 FCITXUTILS_DEPRECATED_EXPORT std::string baseName(const std::string &path) {
26  return baseName(std::string_view(path));
27 }
28 
29 FCITXUTILS_DEPRECATED_EXPORT int64_t modifiedTime(const std::string &path) {
30  return modifiedTime(std::filesystem::path(path));
31 }
32 
33 UniqueFilePtr openFD(StandardPathFile &file, const char *modes) {
34  if (!file.isValid()) {
35  return nullptr;
36  }
37  UniqueFilePtr fd(fdopen(file.fd(), modes));
38  if (fd) {
39  file.release();
40  }
41  return fd;
42 }
43 
44 } // namespace fcitx::fs
std::string baseName(std::string_view path)
Get base file name of path.
Definition: fs.cpp:215
Simple file system related API for checking file status.
Definition: fs.cpp:32
Utility class that wraps around UnixFD.
Definition: standardpath.h:153
Utility classes to handle XDG file path.
bool makePath(const std::filesystem::path &path)
Create directory recursively.
Definition: fs.cpp:179
UniqueFilePtr openFD(UnixFD &fd, const char *modes)
open the unix fd with fdopen.
Definition: fs.cpp:282
int64_t modifiedTime(const std::filesystem::path &path)
Return modified time in seconds of given path.
Definition: fs.cpp:271