diff --git a/libcxx/src/filesystem/error.h b/libcxx/src/filesystem/error.h --- a/libcxx/src/filesystem/error.h +++ b/libcxx/src/filesystem/error.h @@ -28,20 +28,13 @@ # include // ERROR_* macros #endif -// TODO: Check whether these functions actually need internal linkage, or if they can be made normal header functions -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-template") - _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM namespace detail { -namespace { #if defined(_LIBCPP_WIN32API) -errc __win_err_to_errc(int err) { +inline errc __win_err_to_errc(int err) { constexpr struct { DWORD win; errc errc; @@ -105,13 +98,13 @@ #endif // _LIBCPP_WIN32API -error_code capture_errno() { +inline error_code capture_errno() { _LIBCPP_ASSERT(errno != 0, "Expected errno to be non-zero"); return error_code(errno, generic_category()); } #if defined(_LIBCPP_WIN32API) -error_code make_windows_error(int err) { +inline error_code make_windows_error(int err) { return make_error_code(__win_err_to_errc(err)); } #endif @@ -119,27 +112,27 @@ template T error_value(); template <> -_LIBCPP_CONSTEXPR_SINCE_CXX14 void error_value() {} +inline _LIBCPP_CONSTEXPR_SINCE_CXX14 void error_value() {} template <> -bool error_value() { +inline bool error_value() { return false; } #if __SIZEOF_SIZE_T__ != __SIZEOF_LONG_LONG__ template <> -size_t error_value() { +inline size_t error_value() { return size_t(-1); } #endif template <> -uintmax_t error_value() { +inline uintmax_t error_value() { return uintmax_t(-1); } template <> -_LIBCPP_CONSTEXPR_SINCE_CXX14 file_time_type error_value() { +inline _LIBCPP_CONSTEXPR_SINCE_CXX14 file_time_type error_value() { return file_time_type::min(); } template <> -path error_value() { +inline path error_value() { return {}; } @@ -238,7 +231,6 @@ ErrorHandler& operator=(ErrorHandler const&) = delete; }; -} // end anonymous namespace } // end namespace detail _LIBCPP_END_NAMESPACE_FILESYSTEM diff --git a/libcxx/src/filesystem/file_descriptor.h b/libcxx/src/filesystem/file_descriptor.h --- a/libcxx/src/filesystem/file_descriptor.h +++ b/libcxx/src/filesystem/file_descriptor.h @@ -31,22 +31,15 @@ # include #endif // defined(_LIBCPP_WIN32API) -// TODO: Check whether these functions actually need internal linkage, or if they can be made normal header functions -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-template") - _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM namespace detail { -namespace { #if !defined(_LIBCPP_WIN32API) #if defined(DT_BLK) template -static file_type get_file_type(DirEntT* ent, int) { +file_type get_file_type(DirEntT* ent, int) { switch (ent->d_type) { case DT_BLK: return file_type::block; @@ -73,11 +66,11 @@ #endif // defined(DT_BLK) template -static file_type get_file_type(DirEntT*, long) { +file_type get_file_type(DirEntT*, long) { return file_type::none; } -static pair posix_readdir(DIR* dir_stream, +inline pair posix_readdir(DIR* dir_stream, error_code& ec) { struct dirent* dir_entry_ptr = nullptr; errno = 0; // zero errno in order to detect errors @@ -93,7 +86,7 @@ #else // _LIBCPP_WIN32API -static file_type get_file_type(const WIN32_FIND_DATAW& data) { +inline file_type get_file_type(const WIN32_FIND_DATAW& data) { if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && data.dwReserved0 == IO_REPARSE_TAG_SYMLINK) return file_type::symlink; @@ -101,10 +94,10 @@ return file_type::directory; return file_type::regular; } -static uintmax_t get_file_size(const WIN32_FIND_DATAW& data) { +inline uintmax_t get_file_size(const WIN32_FIND_DATAW& data) { return (static_cast(data.nFileSizeHigh) << 32) + data.nFileSizeLow; } -static file_time_type get_write_time(const WIN32_FIND_DATAW& data) { +inline file_time_type get_write_time(const WIN32_FIND_DATAW& data) { ULARGE_INTEGER tmp; const FILETIME& time = data.ftLastWriteTime; tmp.u.LowPart = time.dwLowDateTime; @@ -175,12 +168,12 @@ explicit FileDescriptor(const path* p, int descriptor = -1) : name(*p), fd(descriptor) {} }; -perms posix_get_perms(const StatT& st) noexcept { +inline perms posix_get_perms(const StatT& st) noexcept { return static_cast(st.st_mode) & perms::mask; } -file_status create_file_status(error_code& m_ec, path const& p, - const StatT& path_stat, error_code* ec) { +inline file_status create_file_status(error_code& m_ec, path const& p, + const StatT& path_stat, error_code* ec) { if (ec) *ec = m_ec; if (m_ec && (m_ec.value() == ENOENT || m_ec.value() == ENOTDIR)) { @@ -215,32 +208,32 @@ return fs_tmp; } -file_status posix_stat(path const& p, StatT& path_stat, error_code* ec) { +inline file_status posix_stat(path const& p, StatT& path_stat, error_code* ec) { error_code m_ec; if (detail::stat(p.c_str(), &path_stat) == -1) m_ec = detail::capture_errno(); return create_file_status(m_ec, p, path_stat, ec); } -file_status posix_stat(path const& p, error_code* ec) { +inline file_status posix_stat(path const& p, error_code* ec) { StatT path_stat; return posix_stat(p, path_stat, ec); } -file_status posix_lstat(path const& p, StatT& path_stat, error_code* ec) { +inline file_status posix_lstat(path const& p, StatT& path_stat, error_code* ec) { error_code m_ec; if (detail::lstat(p.c_str(), &path_stat) == -1) m_ec = detail::capture_errno(); return create_file_status(m_ec, p, path_stat, ec); } -file_status posix_lstat(path const& p, error_code* ec) { +inline file_status posix_lstat(path const& p, error_code* ec) { StatT path_stat; return posix_lstat(p, path_stat, ec); } // http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html -bool posix_ftruncate(const FileDescriptor& fd, off_t to_size, error_code& ec) { +inline bool posix_ftruncate(const FileDescriptor& fd, off_t to_size, error_code& ec) { if (detail::ftruncate(fd.fd, to_size) == -1) { ec = capture_errno(); return true; @@ -249,7 +242,7 @@ return false; } -bool posix_fchmod(const FileDescriptor& fd, const StatT& st, error_code& ec) { +inline bool posix_fchmod(const FileDescriptor& fd, const StatT& st, error_code& ec) { if (detail::fchmod(fd.fd, st.st_mode) == -1) { ec = capture_errno(); return true; @@ -258,11 +251,11 @@ return false; } -bool stat_equivalent(const StatT& st1, const StatT& st2) { +inline bool stat_equivalent(const StatT& st1, const StatT& st2) { return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); } -file_status FileDescriptor::refresh_status(error_code& ec) { +inline file_status FileDescriptor::refresh_status(error_code& ec) { // FD must be open and good. m_status = file_status{}; m_stat = {}; @@ -273,11 +266,8 @@ return m_status; } -} // namespace } // end namespace detail _LIBCPP_END_NAMESPACE_FILESYSTEM -_LIBCPP_DIAGNOSTIC_POP - #endif // FILESYSTEM_FILE_DESCRIPTOR_H diff --git a/libcxx/src/filesystem/format_string.h b/libcxx/src/filesystem/format_string.h --- a/libcxx/src/filesystem/format_string.h +++ b/libcxx/src/filesystem/format_string.h @@ -25,19 +25,11 @@ # define PATH_CSTR_FMT "\"%s\"" #endif -// TODO: Check whether these functions actually need internal linkage, or if they can be made normal header functions -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-template") - _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM namespace detail { -namespace { -_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 0) -string vformat_string(const char* msg, va_list ap) { +inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 0) string vformat_string(const char* msg, va_list ap) { array buf; va_list apcopy; @@ -60,8 +52,7 @@ return result; } -_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) -string format_string(const char* msg, ...) { +inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) string format_string(const char* msg, ...) { string ret; va_list ap; va_start(ap, msg); @@ -79,11 +70,8 @@ return ret; } -} // end anonymous namespace } // end namespace detail _LIBCPP_END_NAMESPACE_FILESYSTEM -_LIBCPP_DIAGNOSTIC_POP - #endif // FILESYSTEM_FORMAT_STRING_H diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -350,7 +350,7 @@ return err.report(m_ec); } - if (!copy_file_impl(from_fd, to_fd, m_ec)) { + if (!detail::copy_file_impl(from_fd, to_fd, m_ec)) { // FIXME: Remove the dest file if we failed, and it didn't exist previously. return err.report(m_ec); } diff --git a/libcxx/src/filesystem/path_parser.h b/libcxx/src/filesystem/path_parser.h --- a/libcxx/src/filesystem/path_parser.h +++ b/libcxx/src/filesystem/path_parser.h @@ -17,17 +17,9 @@ #include "format_string.h" -// TODO: Check whether these functions actually need internal linkage, or if they can be made normal header functions -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-template") - _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM -namespace { - -bool isSeparator(path::value_type C) { +inline bool isSeparator(path::value_type C) { if (C == '/') return true; #if defined(_LIBCPP_WIN32API) @@ -37,7 +29,7 @@ return false; } -bool isDriveLetter(path::value_type C) { +inline bool isDriveLetter(path::value_type C) { return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z'); } @@ -356,7 +348,7 @@ } }; -string_view_pair separate_filename(string_view_t const& s) { +inline string_view_pair separate_filename(string_view_t const& s) { if (s == PATHSTR(".") || s == PATHSTR("..") || s.empty()) return string_view_pair{s, PATHSTR("")}; auto pos = s.find_last_of('.'); @@ -365,15 +357,12 @@ return string_view_pair{s.substr(0, pos), s.substr(pos)}; } -string_view_t createView(PosPtr S, PosPtr E) noexcept { +inline string_view_t createView(PosPtr S, PosPtr E) noexcept { return {S, static_cast(E - S) + 1}; } } // namespace parser -} // namespace _LIBCPP_END_NAMESPACE_FILESYSTEM -_LIBCPP_DIAGNOSTIC_POP - #endif // PATH_PARSER_H diff --git a/libcxx/src/filesystem/posix_compat.h b/libcxx/src/filesystem/posix_compat.h --- a/libcxx/src/filesystem/posix_compat.h +++ b/libcxx/src/filesystem/posix_compat.h @@ -75,16 +75,9 @@ }; #endif -// TODO: Check whether these functions actually need internal linkage, or if they can be made normal header functions -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-template") - _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM namespace detail { -namespace { #if defined(_LIBCPP_WIN32API) // Various C runtime versions (UCRT, or the legacy msvcrt.dll used by @@ -168,21 +161,21 @@ // (1601) to the Unix epoch (1970). #define FILE_TIME_OFFSET_SECS (uint64_t(369 * 365 + 89) * (24 * 60 * 60)) -TimeSpec filetime_to_timespec(LARGE_INTEGER li) { +inline TimeSpec filetime_to_timespec(LARGE_INTEGER li) { TimeSpec ret; ret.tv_sec = li.QuadPart / 10000000 - FILE_TIME_OFFSET_SECS; ret.tv_nsec = (li.QuadPart % 10000000) * 100; return ret; } -TimeSpec filetime_to_timespec(FILETIME ft) { +inline TimeSpec filetime_to_timespec(FILETIME ft) { LARGE_INTEGER li; li.LowPart = ft.dwLowDateTime; li.HighPart = ft.dwHighDateTime; return filetime_to_timespec(li); } -FILETIME timespec_to_filetime(TimeSpec ts) { +inline FILETIME timespec_to_filetime(TimeSpec ts) { LARGE_INTEGER li; li.QuadPart = ts.tv_nsec / 100 + (ts.tv_sec + FILE_TIME_OFFSET_SECS) * 10000000; @@ -192,7 +185,7 @@ return ft; } -int set_errno(int e = GetLastError()) { +inline int set_errno(int e = GetLastError()) { errno = static_cast(__win_err_to_errc(e)); return -1; } @@ -215,7 +208,7 @@ HANDLE h; }; -int stat_handle(HANDLE h, StatT *buf) { +inline int stat_handle(HANDLE h, StatT *buf) { FILE_BASIC_INFO basic; if (!GetFileInformationByHandleEx(h, FileBasicInfo, &basic, sizeof(basic))) return set_errno(); @@ -253,7 +246,7 @@ return 0; } -int stat_file(const wchar_t *path, StatT *buf, DWORD flags) { +inline int stat_file(const wchar_t *path, StatT *buf, DWORD flags) { WinHandle h(path, FILE_READ_ATTRIBUTES, flags); if (!h) return set_errno(); @@ -261,24 +254,24 @@ return ret; } -int stat(const wchar_t *path, StatT *buf) { return stat_file(path, buf, 0); } +inline int stat(const wchar_t *path, StatT *buf) { return stat_file(path, buf, 0); } -int lstat(const wchar_t *path, StatT *buf) { +inline int lstat(const wchar_t *path, StatT *buf) { return stat_file(path, buf, FILE_FLAG_OPEN_REPARSE_POINT); } -int fstat(int fd, StatT *buf) { +inline int fstat(int fd, StatT *buf) { HANDLE h = reinterpret_cast(_get_osfhandle(fd)); return stat_handle(h, buf); } -int mkdir(const wchar_t *path, int permissions) { +inline int mkdir(const wchar_t *path, int permissions) { (void)permissions; return _wmkdir(path); } -int symlink_file_dir(const wchar_t *oldname, const wchar_t *newname, - bool is_dir) { +inline int symlink_file_dir(const wchar_t *oldname, const wchar_t *newname, + bool is_dir) { path dest(oldname); dest.make_preferred(); oldname = dest.c_str(); @@ -294,21 +287,21 @@ return set_errno(); } -int symlink_file(const wchar_t *oldname, const wchar_t *newname) { +inline int symlink_file(const wchar_t *oldname, const wchar_t *newname) { return symlink_file_dir(oldname, newname, false); } -int symlink_dir(const wchar_t *oldname, const wchar_t *newname) { +inline int symlink_dir(const wchar_t *oldname, const wchar_t *newname) { return symlink_file_dir(oldname, newname, true); } -int link(const wchar_t *oldname, const wchar_t *newname) { +inline int link(const wchar_t *oldname, const wchar_t *newname) { if (CreateHardLinkW(newname, oldname, nullptr)) return 0; return set_errno(); } -int remove(const wchar_t *path) { +inline int remove(const wchar_t *path) { detail::WinHandle h(path, DELETE, FILE_FLAG_OPEN_REPARSE_POINT); if (!h) return set_errno(); @@ -319,7 +312,7 @@ return 0; } -int truncate_handle(HANDLE h, off_t length) { +inline int truncate_handle(HANDLE h, off_t length) { LARGE_INTEGER size_param; size_param.QuadPart = length; if (!SetFilePointerEx(h, size_param, 0, FILE_BEGIN)) @@ -329,19 +322,19 @@ return 0; } -int ftruncate(int fd, off_t length) { +inline int ftruncate(int fd, off_t length) { HANDLE h = reinterpret_cast(_get_osfhandle(fd)); return truncate_handle(h, length); } -int truncate(const wchar_t *path, off_t length) { +inline int truncate(const wchar_t *path, off_t length) { detail::WinHandle h(path, GENERIC_WRITE, 0); if (!h) return set_errno(); return truncate_handle(h, length); } -int rename(const wchar_t *from, const wchar_t *to) { +inline int rename(const wchar_t *from, const wchar_t *to) { if (!(MoveFileExW(from, to, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH))) @@ -352,8 +345,8 @@ template int open(const wchar_t *filename, Args... args) { return _wopen(filename, args...); } -int close(int fd) { return _close(fd); } -int chdir(const wchar_t *path) { return _wchdir(path); } +inline int close(int fd) { return _close(fd); } +inline int chdir(const wchar_t *path) { return _wchdir(path); } struct StatVFS { uint64_t f_frsize; @@ -362,7 +355,7 @@ uint64_t f_bavail; }; -int statvfs(const wchar_t *p, StatVFS *buf) { +inline int statvfs(const wchar_t *p, StatVFS *buf) { path dir = p; while (true) { error_code local_ec; @@ -388,9 +381,9 @@ return 0; } -wchar_t *getcwd(wchar_t *buff, size_t size) { return _wgetcwd(buff, size); } +inline wchar_t *getcwd(wchar_t *buff, size_t size) { return _wgetcwd(buff, size); } -wchar_t *realpath(const wchar_t *path, wchar_t *resolved_name) { +inline wchar_t *realpath(const wchar_t *path, wchar_t *resolved_name) { // Only expected to be used with us allocating the buffer. _LIBCPP_ASSERT(resolved_name == nullptr, "Windows realpath() assumes a null resolved_name"); @@ -431,7 +424,7 @@ #define AT_SYMLINK_NOFOLLOW 1 using ModeT = int; -int fchmod_handle(HANDLE h, int perms) { +inline int fchmod_handle(HANDLE h, int perms) { FILE_BASIC_INFO basic; if (!GetFileInformationByHandleEx(h, FileBasicInfo, &basic, sizeof(basic))) return set_errno(); @@ -445,7 +438,7 @@ return 0; } -int fchmodat(int /*fd*/, const wchar_t *path, int perms, int flag) { +inline int fchmodat(int /*fd*/, const wchar_t *path, int perms, int flag) { DWORD attributes = GetFileAttributesW(path); if (attributes == INVALID_FILE_ATTRIBUTES) return set_errno(); @@ -472,7 +465,7 @@ return 0; } -int fchmod(int fd, int perms) { +inline int fchmod(int fd, int perms) { HANDLE h = reinterpret_cast(_get_osfhandle(fd)); return fchmod_handle(h, perms); } @@ -480,7 +473,7 @@ #define MAX_SYMLINK_SIZE MAXIMUM_REPARSE_DATA_BUFFER_SIZE using SSizeT = ::int64_t; -SSizeT readlink(const wchar_t *path, wchar_t *ret_buf, size_t bufsize) { +inline SSizeT readlink(const wchar_t *path, wchar_t *ret_buf, size_t bufsize) { uint8_t buf[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; detail::WinHandle h(path, FILE_READ_ATTRIBUTES, FILE_FLAG_OPEN_REPARSE_POINT); if (!h) @@ -524,10 +517,10 @@ } #else -int symlink_file(const char *oldname, const char *newname) { +inline int symlink_file(const char *oldname, const char *newname) { return ::symlink(oldname, newname); } -int symlink_dir(const char *oldname, const char *newname) { +inline int symlink_dir(const char *oldname, const char *newname) { return ::symlink(oldname, newname); } using ::chdir; @@ -559,11 +552,8 @@ #endif -} // namespace } // end namespace detail _LIBCPP_END_NAMESPACE_FILESYSTEM -_LIBCPP_DIAGNOSTIC_POP - #endif // POSIX_COMPAT_H diff --git a/libcxx/src/filesystem/time_utils.h b/libcxx/src/filesystem/time_utils.h --- a/libcxx/src/filesystem/time_utils.h +++ b/libcxx/src/filesystem/time_utils.h @@ -36,16 +36,9 @@ # define _LIBCPP_USE_UTIMENSAT #endif -// TODO: Check whether these functions actually need internal linkage, or if they can be made normal header functions -_LIBCPP_DIAGNOSTIC_PUSH -_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-function") -_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-template") - _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM namespace detail { -namespace { using chrono::duration; using chrono::duration_cast; @@ -284,8 +277,8 @@ } #if defined(_LIBCPP_USE_UTIMENSAT) -bool posix_utimensat(const path& p, std::array const& TS, - error_code& ec) { +inline bool posix_utimensat(const path& p, std::array const& TS, + error_code& ec) { if (::utimensat(AT_FDCWD, p.c_str(), TS.data(), 0) == -1) { ec = capture_errno(); return true; @@ -294,8 +287,8 @@ } #endif -bool set_file_times(const path& p, std::array const& TS, - error_code& ec) { +inline bool set_file_times(const path& p, std::array const& TS, + error_code& ec) { #if !defined(_LIBCPP_USE_UTIMENSAT) return posix_utimes(p, TS, ec); #else @@ -305,8 +298,8 @@ #endif // !_LIBCPP_WIN32API -file_time_type __extract_last_write_time(const path& p, const StatT& st, - error_code* ec) { +inline file_time_type __extract_last_write_time(const path& p, const StatT& st, + error_code* ec) { using detail::fs_time; ErrorHandler err("last_write_time", ec, &p); @@ -317,11 +310,8 @@ return fs_time::convert_from_timespec(ts); } -} // namespace } // end namespace detail _LIBCPP_END_NAMESPACE_FILESYSTEM -_LIBCPP_DIAGNOSTIC_POP - #endif // FILESYSTEM_TIME_UTILS_H