fs/StandardDirectory: add noexcept
This commit is contained in:
parent
863a28daa3
commit
9669ea6a12
@ -72,9 +72,9 @@ class PasswdEntry
|
|||||||
|
|
||||||
passwd *result{nullptr};
|
passwd *result{nullptr};
|
||||||
public:
|
public:
|
||||||
PasswdEntry() = default;
|
PasswdEntry() noexcept = default;
|
||||||
|
|
||||||
bool ReadByName(const char *name) {
|
bool ReadByName(const char *name) noexcept {
|
||||||
#ifdef HAVE_GETPWNAM_R
|
#ifdef HAVE_GETPWNAM_R
|
||||||
getpwnam_r(name, &pw, buf.data(), buf.size(), &result);
|
getpwnam_r(name, &pw, buf.data(), buf.size(), &result);
|
||||||
#else
|
#else
|
||||||
@ -83,7 +83,7 @@ public:
|
|||||||
return result != nullptr;
|
return result != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadByUid(uid_t uid) {
|
bool ReadByUid(uid_t uid) noexcept {
|
||||||
#ifdef HAVE_GETPWUID_R
|
#ifdef HAVE_GETPWUID_R
|
||||||
getpwuid_r(uid, &pw, buf.data(), buf.size(), &result);
|
getpwuid_r(uid, &pw, buf.data(), buf.size(), &result);
|
||||||
#else
|
#else
|
||||||
@ -92,7 +92,7 @@ public:
|
|||||||
return result != nullptr;
|
return result != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const passwd *operator->() {
|
const passwd *operator->() noexcept {
|
||||||
assert(result != nullptr);
|
assert(result != nullptr);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -100,21 +100,25 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ANDROID
|
#ifndef ANDROID
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
static inline bool
|
static inline bool
|
||||||
IsValidPathString(PathTraitsFS::const_pointer path)
|
IsValidPathString(PathTraitsFS::const_pointer path) noexcept
|
||||||
{
|
{
|
||||||
return path != nullptr && *path != '\0';
|
return path != nullptr && *path != '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
static inline bool
|
static inline bool
|
||||||
IsValidDir(PathTraitsFS::const_pointer dir)
|
IsValidDir(PathTraitsFS::const_pointer dir) noexcept
|
||||||
{
|
{
|
||||||
return PathTraitsFS::IsAbsolute(dir) &&
|
return PathTraitsFS::IsAbsolute(dir) &&
|
||||||
DirectoryExists(Path::FromFS(dir));
|
DirectoryExists(Path::FromFS(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
static inline AllocatedPath
|
static inline AllocatedPath
|
||||||
SafePathFromFS(PathTraitsFS::const_pointer dir)
|
SafePathFromFS(PathTraitsFS::const_pointer dir) noexcept
|
||||||
{
|
{
|
||||||
if (IsValidPathString(dir) && IsValidDir(dir))
|
if (IsValidPathString(dir) && IsValidDir(dir))
|
||||||
return AllocatedPath::FromFS(dir);
|
return AllocatedPath::FromFS(dir);
|
||||||
@ -123,7 +127,10 @@ SafePathFromFS(PathTraitsFS::const_pointer dir)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static AllocatedPath GetStandardDir(int folder_id)
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
static AllocatedPath
|
||||||
|
GetStandardDir(int folder_id) noexcept
|
||||||
{
|
{
|
||||||
std::array<PathTraitsFS::value_type, MAX_PATH> dir;
|
std::array<PathTraitsFS::value_type, MAX_PATH> dir;
|
||||||
auto ret = SHGetFolderPath(nullptr, folder_id | CSIDL_FLAG_DONT_VERIFY,
|
auto ret = SHGetFolderPath(nullptr, folder_id | CSIDL_FLAG_DONT_VERIFY,
|
||||||
@ -132,13 +139,14 @@ static AllocatedPath GetStandardDir(int folder_id)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
return SafePathFromFS(dir.data());
|
return SafePathFromFS(dir.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_XDG
|
#ifdef USE_XDG
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ParseConfigLine(std::string_view line, std::string_view dir_name,
|
ParseConfigLine(std::string_view line, std::string_view dir_name,
|
||||||
AllocatedPath &result_dir)
|
AllocatedPath &result_dir) noexcept
|
||||||
{
|
{
|
||||||
// strip leading white space
|
// strip leading white space
|
||||||
line = StripLeft(line);
|
line = StripLeft(line);
|
||||||
@ -248,7 +256,7 @@ AllocatedPath
|
|||||||
GetUserMusicDir() noexcept
|
GetUserMusicDir() noexcept
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return GetStandardDir(CSIDL_MYMUSIC);
|
return GetStandardDir(CSIDL_MYMUSIC);
|
||||||
#elif defined(USE_XDG)
|
#elif defined(USE_XDG)
|
||||||
return GetUserDir("XDG_MUSIC_DIR");
|
return GetUserDir("XDG_MUSIC_DIR");
|
||||||
#elif defined(ANDROID)
|
#elif defined(ANDROID)
|
||||||
|
Loading…
Reference in New Issue
Block a user