diff options
Diffstat (limited to 'src/filesystem')
-rw-r--r-- | src/filesystem/directory_iterator.cpp | 10 | ||||
-rw-r--r-- | src/filesystem/filesystem_common.h | 7 | ||||
-rw-r--r-- | src/filesystem/int128_builtins.cpp | 7 | ||||
-rw-r--r-- | src/filesystem/operations.cpp | 42 |
4 files changed, 44 insertions, 22 deletions
diff --git a/src/filesystem/directory_iterator.cpp b/src/filesystem/directory_iterator.cpp index f0d807a03db6..ca88dee06402 100644 --- a/src/filesystem/directory_iterator.cpp +++ b/src/filesystem/directory_iterator.cpp @@ -1,9 +1,8 @@ //===------------------ directory_iterator.cpp ----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -25,6 +24,8 @@ namespace detail { namespace { #if !defined(_LIBCPP_WIN32API) + +#if defined(DT_BLK) template <class DirEntT, class = decltype(DirEntT::d_type)> static file_type get_file_type(DirEntT* ent, int) { switch (ent->d_type) { @@ -50,6 +51,7 @@ static file_type get_file_type(DirEntT* ent, int) { } return file_type::none; } +#endif // defined(DT_BLK) template <class DirEntT> static file_type get_file_type(DirEntT* ent, long) { diff --git a/src/filesystem/filesystem_common.h b/src/filesystem/filesystem_common.h index 40419ee35e6a..fe5c42f5e6d0 100644 --- a/src/filesystem/filesystem_common.h +++ b/src/filesystem/filesystem_common.h @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===//// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===//// diff --git a/src/filesystem/int128_builtins.cpp b/src/filesystem/int128_builtins.cpp index 66adbdd2dc89..a55540fe276e 100644 --- a/src/filesystem/int128_builtins.cpp +++ b/src/filesystem/int128_builtins.cpp @@ -1,9 +1,8 @@ /*===-- int128_builtins.cpp - Implement __muloti4 --------------------------=== * - * The LLVM Compiler Infrastructure - * - * This file is dual licensed under the MIT and the University of Illinois Open - * Source Licenses. See LICENSE.TXT for details. + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception * * ===----------------------------------------------------------------------=== * diff --git a/src/filesystem/operations.cpp b/src/filesystem/operations.cpp index b41061888724..69350ddfe9da 100644 --- a/src/filesystem/operations.cpp +++ b/src/filesystem/operations.cpp @@ -1,9 +1,8 @@ //===--------------------- filesystem/ops.cpp -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -45,6 +44,10 @@ #include <sys/time.h> // for gettimeofday and timeval #endif // !defined(CLOCK_REALTIME) +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "rt") +#endif + #if defined(_LIBCPP_COMPILER_GCC) #if _GNUC_VER < 500 #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -543,11 +546,19 @@ path __canonical(path const& orig_p, error_code* ec) { ErrorHandler<path> err("canonical", ec, &orig_p, &cwd); path p = __do_absolute(orig_p, &cwd, ec); +#if _POSIX_VERSION >= 200112 + std::unique_ptr<char, decltype(&::free)> + hold(::realpath(p.c_str(), nullptr), &::free); + if (hold.get() == nullptr) + return err.report(capture_errno()); + return {hold.get()}; +#else char buff[PATH_MAX + 1]; char* ret; if ((ret = ::realpath(p.c_str(), buff)) == nullptr) return err.report(capture_errno()); return {ret}; +#endif } void __copy(const path& from, const path& to, copy_options options, @@ -1089,16 +1100,27 @@ void __permissions(const path& p, perms prms, perm_options opts, path __read_symlink(const path& p, error_code* ec) { ErrorHandler<path> err("read_symlink", ec, &p); - char buff[PATH_MAX + 1]; - error_code m_ec; - ::ssize_t ret; - if ((ret = ::readlink(p.c_str(), buff, PATH_MAX)) == -1) { +#ifdef PATH_MAX + struct NullDeleter { void operator()(void*) const {} }; + const size_t size = PATH_MAX + 1; + char stack_buff[size]; + auto buff = std::unique_ptr<char[], NullDeleter>(stack_buff); +#else + StatT sb; + if (::lstat(p.c_str(), &sb) == -1) { return err.report(capture_errno()); } - _LIBCPP_ASSERT(ret <= PATH_MAX, "TODO"); + const size_t size = sb.st_size + 1; + auto buff = unique_ptr<char[]>(new char[size]); +#endif + ::ssize_t ret; + if ((ret = ::readlink(p.c_str(), buff.get(), size)) == -1) + return err.report(capture_errno()); _LIBCPP_ASSERT(ret > 0, "TODO"); + if (static_cast<size_t>(ret) >= size) + return err.report(errc::value_too_large); buff[ret] = 0; - return {buff}; + return {buff.get()}; } bool __remove(const path& p, error_code* ec) { |