fs/FileInfo: add `constexpr` and `noexcept`
This commit is contained in:
parent
19c73680cf
commit
51c0a03e94
|
@ -1,8 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_FS_FILE_INFO_HXX
|
||||
#define MPD_FS_FILE_INFO_HXX
|
||||
#pragma once
|
||||
|
||||
#include "Path.hxx"
|
||||
#include "lib/fmt/PathFormatter.hxx"
|
||||
|
@ -19,7 +18,7 @@
|
|||
|
||||
class FileInfo {
|
||||
friend bool GetFileInfo(Path path, FileInfo &info,
|
||||
bool follow_symlinks);
|
||||
bool follow_symlinks) noexcept;
|
||||
friend class FileReader;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -29,7 +28,7 @@ class FileInfo {
|
|||
#endif
|
||||
|
||||
public:
|
||||
FileInfo() = default;
|
||||
constexpr FileInfo() noexcept = default;
|
||||
|
||||
FileInfo(Path path, bool follow_symlinks=true) {
|
||||
if (!GetFileInfo(path, *this, follow_symlinks)) {
|
||||
|
@ -41,7 +40,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool IsRegular() const {
|
||||
constexpr bool IsRegular() const noexcept {
|
||||
#ifdef _WIN32
|
||||
return (data.dwFileAttributes &
|
||||
(FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)) == 0;
|
||||
|
@ -50,7 +49,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
bool IsDirectory() const {
|
||||
constexpr bool IsDirectory() const noexcept {
|
||||
#ifdef _WIN32
|
||||
return data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
||||
#else
|
||||
|
@ -58,7 +57,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
uint64_t GetSize() const {
|
||||
constexpr uint64_t GetSize() const noexcept {
|
||||
#ifdef _WIN32
|
||||
return ConstructUint64(data.nFileSizeLow, data.nFileSizeHigh);
|
||||
#else
|
||||
|
@ -66,7 +65,8 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point GetModificationTime() const {
|
||||
[[gnu::pure]]
|
||||
std::chrono::system_clock::time_point GetModificationTime() const noexcept {
|
||||
#ifdef _WIN32
|
||||
return FileTimeToChrono(data.ftLastWriteTime);
|
||||
#else
|
||||
|
@ -75,26 +75,26 @@ public:
|
|||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
uid_t GetUid() const {
|
||||
constexpr uid_t GetUid() const noexcept {
|
||||
return st.st_uid;
|
||||
}
|
||||
|
||||
mode_t GetMode() const {
|
||||
constexpr mode_t GetMode() const noexcept {
|
||||
return st.st_mode;
|
||||
}
|
||||
|
||||
dev_t GetDevice() const {
|
||||
constexpr dev_t GetDevice() const noexcept {
|
||||
return st.st_dev;
|
||||
}
|
||||
|
||||
ino_t GetInode() const {
|
||||
constexpr ino_t GetInode() const noexcept {
|
||||
return st.st_ino;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
inline bool
|
||||
GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true)
|
||||
GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true) noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
(void)follow_symlinks;
|
||||
|
@ -107,5 +107,3 @@ GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true)
|
|||
return ret == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue