[llvm] r310078 - [Support] Remove getPathFromOpenFD, it was unused
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 4 10:43:49 PDT 2017
Author: rnk
Date: Fri Aug 4 10:43:49 2017
New Revision: 310078
URL: http://llvm.org/viewvc/llvm-project?rev=310078&view=rev
Log:
[Support] Remove getPathFromOpenFD, it was unused
Summary:
It was added to support clang warnings about includes with case
mismatches, but it ended up not being necessary.
Reviewers: twoh, rafael
Subscribers: hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D36328
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
llvm/trunk/lib/Support/Unix/Path.inc
llvm/trunk/lib/Support/Windows/Path.inc
llvm/trunk/unittests/Support/Path.cpp
Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=310078&r1=310077&r2=310078&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Fri Aug 4 10:43:49 2017
@@ -685,12 +685,6 @@ std::error_code createTemporaryFile(cons
std::error_code createUniqueDirectory(const Twine &Prefix,
SmallVectorImpl<char> &ResultPath);
-/// @brief Fetch a path to an open file, as specified by a file descriptor
-///
-/// @param FD File descriptor to a currently open file
-/// @param ResultPath The buffer into which to write the path
-std::error_code getPathFromOpenFD(int FD, SmallVectorImpl<char> &ResultPath);
-
enum OpenFlags : unsigned {
F_None = 0,
Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=310078&r1=310077&r2=310078&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Fri Aug 4 10:43:49 2017
@@ -807,53 +807,6 @@ std::error_code openFileForWrite(const T
return std::error_code();
}
-std::error_code getPathFromOpenFD(int FD, SmallVectorImpl<char> &ResultPath) {
- if (FD < 0)
- return make_error_code(errc::bad_file_descriptor);
-
-#if defined(F_GETPATH)
- // When F_GETPATH is availble, it is the quickest way to get
- // the path from a file descriptor.
- ResultPath.reserve(MAXPATHLEN);
- if (::fcntl(FD, F_GETPATH, ResultPath.begin()) == -1)
- return std::error_code(errno, std::generic_category());
-
- ResultPath.set_size(strlen(ResultPath.begin()));
-#else
- // If we have a /proc filesystem mounted, we can quickly establish the
- // real name of the file with readlink. Otherwise, we don't know how to
- // get the filename from a file descriptor. Give up.
- if (!fs::hasProcSelfFD())
- return make_error_code(errc::function_not_supported);
-
- ResultPath.reserve(PATH_MAX);
- char ProcPath[64];
- snprintf(ProcPath, sizeof(ProcPath), "/proc/self/fd/%d", FD);
- ssize_t CharCount = ::readlink(ProcPath, ResultPath.begin(), ResultPath.capacity());
- if (CharCount < 0)
- return std::error_code(errno, std::generic_category());
-
- // Was the filename truncated?
- if (static_cast<size_t>(CharCount) == ResultPath.capacity()) {
- // Use lstat to get the size of the filename
- struct stat sb;
- if (::lstat(ProcPath, &sb) < 0)
- return std::error_code(errno, std::generic_category());
-
- ResultPath.reserve(sb.st_size + 1);
- CharCount = ::readlink(ProcPath, ResultPath.begin(), ResultPath.capacity());
- if (CharCount < 0)
- return std::error_code(errno, std::generic_category());
-
- // Test for race condition: did the link size change?
- if (CharCount > sb.st_size)
- return std::error_code(ENAMETOOLONG, std::generic_category());
- }
- ResultPath.set_size(static_cast<size_t>(CharCount));
-#endif
- return std::error_code();
-}
-
template <typename T>
static std::error_code remove_directories_impl(const T &Entry,
bool IgnoreErrors) {
Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=310078&r1=310077&r2=310078&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Fri Aug 4 10:43:49 2017
@@ -959,42 +959,6 @@ std::error_code openFileForWrite(const T
return std::error_code();
}
-std::error_code getPathFromOpenFD(int FD, SmallVectorImpl<char> &ResultPath) {
- HANDLE FileHandle = reinterpret_cast<HANDLE>(::_get_osfhandle(FD));
- if (FileHandle == INVALID_HANDLE_VALUE)
- return make_error_code(errc::bad_file_descriptor);
-
- DWORD CharCount;
- SmallVector<wchar_t, 1024> TempPath;
- do {
- CharCount = ::GetFinalPathNameByHandleW(FileHandle, TempPath.begin(),
- TempPath.capacity(),
- FILE_NAME_NORMALIZED);
- if (CharCount < TempPath.capacity())
- break;
-
- // Reserve sufficient space for the path as well as the null character. Even
- // though the API does not document that it is required, if we reserve just
- // CharCount space, the function call will not store the resulting path and
- // still report success.
- TempPath.reserve(CharCount + 1);
- } while (true);
-
- if (CharCount == 0)
- return mapWindowsError(::GetLastError());
-
- TempPath.set_size(CharCount);
-
- // On earlier Windows releases, the character count includes the terminating
- // null.
- if (TempPath.back() == L'\0') {
- --CharCount;
- TempPath.pop_back();
- }
-
- return windows::UTF16ToUTF8(TempPath.data(), CharCount, ResultPath);
-}
-
std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
// Convert to utf-16.
SmallVector<wchar_t, 128> Path16;
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=310078&r1=310077&r2=310078&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Fri Aug 4 10:43:49 2017
@@ -1145,96 +1145,6 @@ TEST(Support, ReplacePathPrefix) {
EXPECT_EQ(Path, "/foo");
}
-TEST_F(FileSystemTest, PathFromFD) {
- // Create a temp file.
- int FileDescriptor;
- SmallString<64> TempPath;
- ASSERT_NO_ERROR(
- fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath));
- FileRemover Cleanup(TempPath);
-
- // Make sure it exists.
- ASSERT_TRUE(sys::fs::exists(Twine(TempPath)));
-
- // Try to get the path from the file descriptor
- SmallString<64> ResultPath;
- std::error_code ErrorCode =
- fs::getPathFromOpenFD(FileDescriptor, ResultPath);
-
- // If we succeeded, check that the paths are the same (modulo case):
- if (!ErrorCode) {
- // The paths returned by createTemporaryFile and getPathFromOpenFD
- // should reference the same file on disk.
- fs::UniqueID D1, D2;
- ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath), D1));
- ASSERT_NO_ERROR(fs::getUniqueID(Twine(ResultPath), D2));
- ASSERT_EQ(D1, D2);
- }
-
- ::close(FileDescriptor);
-}
-
-TEST_F(FileSystemTest, PathFromFDWin32) {
- // Create a temp file.
- int FileDescriptor;
- SmallString<64> TempPath;
- ASSERT_NO_ERROR(
- fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath));
- FileRemover Cleanup(TempPath);
-
- // Make sure it exists.
- ASSERT_TRUE(sys::fs::exists(Twine(TempPath)));
-
- SmallVector<char, 8> ResultPath;
- std::error_code ErrorCode =
- fs::getPathFromOpenFD(FileDescriptor, ResultPath);
-
- if (!ErrorCode) {
- // Now that we know how much space is required for the path, create a path
- // buffer with exactly enough space (sans null terminator, which should not
- // be present), and call getPathFromOpenFD again to ensure that the API
- // properly handles exactly-sized buffers.
- SmallVector<char, 8> ExactSizedPath(ResultPath.size());
- ErrorCode = fs::getPathFromOpenFD(FileDescriptor, ExactSizedPath);
- ResultPath = ExactSizedPath;
- }
-
- if (!ErrorCode) {
- fs::UniqueID D1, D2;
- ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath), D1));
- ASSERT_NO_ERROR(fs::getUniqueID(Twine(ResultPath), D2));
- ASSERT_EQ(D1, D2);
- }
- ::close(FileDescriptor);
-}
-
-TEST_F(FileSystemTest, PathFromFDUnicode) {
- // Create a temp file.
- int FileDescriptor;
- SmallString<64> TempPath;
-
- // Test Unicode: "<temp directory>/(pi)r^2<temp rand chars>.aleth.0"
- ASSERT_NO_ERROR(
- fs::createTemporaryFile("\xCF\x80r\xC2\xB2",
- "\xE2\x84\xB5.0", FileDescriptor, TempPath));
- FileRemover Cleanup(TempPath);
-
- // Make sure it exists.
- ASSERT_TRUE(sys::fs::exists(Twine(TempPath)));
-
- SmallVector<char, 8> ResultPath;
- std::error_code ErrorCode =
- fs::getPathFromOpenFD(FileDescriptor, ResultPath);
-
- if (!ErrorCode) {
- fs::UniqueID D1, D2;
- ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath), D1));
- ASSERT_NO_ERROR(fs::getUniqueID(Twine(ResultPath), D2));
- ASSERT_EQ(D1, D2);
- }
- ::close(FileDescriptor);
-}
-
TEST_F(FileSystemTest, OpenFileForRead) {
// Create a temp file.
int FileDescriptor;
More information about the llvm-commits
mailing list