From 9d425e7687c1701702a2874e09034ff1e573a769 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Sat, 4 Dec 2010 18:45:32 +0000 Subject: [PATCH] Support/PathV2: Remove redundant calls to make_error_code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120913 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/PathV2.cpp | 64 +++++++++++----------- lib/Support/Unix/PathV2.inc | 42 +++++++-------- lib/Support/Windows/PathV2.inc | 97 +++++++++++++++++----------------- 3 files changed, 101 insertions(+), 102 deletions(-) diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index 829e107b2d5..edb3accbb5f 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -293,28 +293,28 @@ error_code root_path(const StringRef &path, StringRef &result) { if ((++pos != e) && is_separator((*pos)[0])) { // {C:/,//net/}, so get the first two components. result = StringRef(path.begin(), b->size() + pos->size()); - return make_error_code(errc::success); + return success; } else { // just {C:,//net}, return the first component. result = *b; - return make_error_code(errc::success); + return success; } } // POSIX style root directory. if (is_separator((*b)[0])) { result = *b; - return make_error_code(errc::success); + return success; } // No root_path. result = StringRef(); - return make_error_code(errc::success); + return success; } // No path :(. result = StringRef(); - return make_error_code(errc::success); + return success; } error_code root_name(const StringRef &path, StringRef &result) { @@ -332,13 +332,13 @@ error_code root_name(const StringRef &path, StringRef &result) { if (has_net || has_drive) { // just {C:,//net}, return the first component. result = *b; - return make_error_code(errc::success); + return success; } } // No path or no name. result = StringRef(); - return make_error_code(errc::success); + return success; } error_code root_directory(const StringRef &path, StringRef &result) { @@ -358,26 +358,26 @@ error_code root_directory(const StringRef &path, StringRef &result) { // {C:,//net}, skip to the next component. (++pos != e) && is_separator((*pos)[0])) { result = *pos; - return make_error_code(errc::success); + return success; } // POSIX style root directory. if (!has_net && is_separator((*b)[0])) { result = *b; - return make_error_code(errc::success); + return success; } } // No path or no root. result = StringRef(); - return make_error_code(errc::success); + return success; } error_code relative_path(const StringRef &path, StringRef &result) { StringRef root; if (error_code ec = root_path(path, root)) return ec; result = StringRef(path.begin() + root.size(), path.size() - root.size()); - return make_error_code(errc::success); + return success; } error_code append(SmallVectorImpl &path, const Twine &a, @@ -421,7 +421,7 @@ error_code append(SmallVectorImpl &path, const Twine &a, path.append(i->begin(), i->end()); } - return make_error_code(errc::success); + return success; } error_code make_absolute(SmallVectorImpl &path) { @@ -433,7 +433,7 @@ error_code make_absolute(SmallVectorImpl &path) { // Already absolute. if (rootName && rootDirectory) - return make_error_code(errc::success); + return success; // All of the following conditions will need the current directory. SmallString<128> current_dir; @@ -445,7 +445,7 @@ error_code make_absolute(SmallVectorImpl &path) { if (error_code ec = append(current_dir, p)) return ec; // Set path to the result. path.swap(current_dir); - return make_error_code(errc::success); + return success; } if (!rootName && rootDirectory) { @@ -455,7 +455,7 @@ error_code make_absolute(SmallVectorImpl &path) { if (error_code ec = append(curDirRootName, p)) return ec; // Set path to the result. path.swap(curDirRootName); - return make_error_code(errc::success); + return success; } if (rootName && !rootDirectory) { @@ -472,7 +472,7 @@ error_code make_absolute(SmallVectorImpl &path) { if (error_code ec = append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath)) return ec; path.swap(res); - return make_error_code(errc::success); + return success; } llvm_unreachable("All rootName and rootDirectory combinations should have " @@ -485,15 +485,15 @@ error_code parent_path(const StringRef &path, StringRef &result) { result = StringRef(); else result = StringRef(path.data(), end_pos); - return make_error_code(errc::success); + return success; } error_code remove_filename(SmallVectorImpl &path) { size_t end_pos = parent_path_end(StringRef(path.begin(), path.size())); if (end_pos == StringRef::npos) - return make_error_code(errc::success); + return success; path.set_size(end_pos); - return make_error_code(errc::success); + return success; } error_code replace_extension(SmallVectorImpl &path, @@ -513,7 +513,7 @@ error_code replace_extension(SmallVectorImpl &path, // Append extension. path.append(ext.begin(), ext.end()); - return make_error_code(errc::success); + return success; } error_code native(const Twine &path, SmallVectorImpl &result) { @@ -535,12 +535,12 @@ error_code native(const Twine &path, SmallVectorImpl &result) { #else path.toVector(result); #endif - return make_error_code(errc::success); + return success; } error_code filename(const StringRef &path, StringRef &result) { result = *(--end(path)); - return make_error_code(errc::success); + return success; } error_code stem(const StringRef &path, StringRef &result) { @@ -556,7 +556,7 @@ error_code stem(const StringRef &path, StringRef &result) { else result = StringRef(fname.begin(), pos); - return make_error_code(errc::success); + return success; } error_code extension(const StringRef &path, StringRef &result) { @@ -572,7 +572,7 @@ error_code extension(const StringRef &path, StringRef &result) { else result = StringRef(fname.begin() + pos, fname.size() - pos); - return make_error_code(errc::success); + return success; } error_code has_root_name(const Twine &path, bool &result) { @@ -582,7 +582,7 @@ error_code has_root_name(const Twine &path, bool &result) { if (error_code ec = root_name(p, p)) return ec; result = !p.empty(); - return make_error_code(errc::success); + return success; } error_code has_root_directory(const Twine &path, bool &result) { @@ -592,7 +592,7 @@ error_code has_root_directory(const Twine &path, bool &result) { if (error_code ec = root_directory(p, p)) return ec; result = !p.empty(); - return make_error_code(errc::success); + return success; } error_code has_root_path(const Twine &path, bool &result) { @@ -602,7 +602,7 @@ error_code has_root_path(const Twine &path, bool &result) { if (error_code ec = root_path(p, p)) return ec; result = !p.empty(); - return make_error_code(errc::success); + return success; } error_code has_filename(const Twine &path, bool &result) { @@ -612,7 +612,7 @@ error_code has_filename(const Twine &path, bool &result) { if (error_code ec = filename(p, p)) return ec; result = !p.empty(); - return make_error_code(errc::success); + return success; } error_code has_parent_path(const Twine &path, bool &result) { @@ -622,7 +622,7 @@ error_code has_parent_path(const Twine &path, bool &result) { if (error_code ec = parent_path(p, p)) return ec; result = !p.empty(); - return make_error_code(errc::success); + return success; } error_code has_stem(const Twine &path, bool &result) { @@ -632,7 +632,7 @@ error_code has_stem(const Twine &path, bool &result) { if (error_code ec = stem(p, p)) return ec; result = !p.empty(); - return make_error_code(errc::success); + return success; } error_code has_extension(const Twine &path, bool &result) { @@ -642,7 +642,7 @@ error_code has_extension(const Twine &path, bool &result) { if (error_code ec = extension(p, p)) return ec; result = !p.empty(); - return make_error_code(errc::success); + return success; } error_code is_absolute(const Twine &path, bool &result) { @@ -659,7 +659,7 @@ error_code is_absolute(const Twine &path, bool &result) { #endif result = rootDir && rootName; - return make_error_code(errc::success); + return success; } error_code is_relative(const Twine &path, bool &result) { diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc index f71212f5e6e..b5cf724c5ff 100644 --- a/lib/Support/Unix/PathV2.inc +++ b/lib/Support/Unix/PathV2.inc @@ -63,7 +63,7 @@ namespace { result.set_size(0); StringRef d(dir); result.append(d.begin(), d.end()); - return make_error_code(errc::success); + return success; } } @@ -80,7 +80,7 @@ error_code current_path(SmallVectorImpl &result) { return error_code(errno, system_category()); result.set_size(strlen(result.data())); - return make_error_code(errc::success); + return success; } } // end namespace path @@ -143,7 +143,7 @@ error_code copy_file(const Twine &from, const Twine &to, copy_option copt) { if (sz_read < 0) return error_code(errno, system_category()); - return make_error_code(errc::success); + return success; } error_code create_directory(const Twine &path, bool &existed) { @@ -151,13 +151,13 @@ error_code create_directory(const Twine &path, bool &existed) { StringRef p = path.toNullTerminatedStringRef(path_storage); if (::mkdir(p.begin(), 0700) == -1) { - if (errno != EEXIST) + if (errno != errc::file_exists) return error_code(errno, system_category()); existed = true; } else existed = false; - return make_error_code(errc::success); + return success; } error_code create_hard_link(const Twine &to, const Twine &from) { @@ -170,7 +170,7 @@ error_code create_hard_link(const Twine &to, const Twine &from) { if (::link(t.begin(), f.begin()) == -1) return error_code(errno, system_category()); - return make_error_code(errc::success); + return success; } error_code create_symlink(const Twine &to, const Twine &from) { @@ -183,7 +183,7 @@ error_code create_symlink(const Twine &to, const Twine &from) { if (::symlink(t.begin(), f.begin()) == -1) return error_code(errno, system_category()); - return make_error_code(errc::success); + return success; } error_code remove(const Twine &path, bool &existed) { @@ -191,13 +191,13 @@ error_code remove(const Twine &path, bool &existed) { StringRef p = path.toNullTerminatedStringRef(path_storage); if (::remove(p.begin()) == -1) { - if (errno != ENOENT) + if (errno != errc::no_such_file_or_directory) return error_code(errno, system_category()); existed = false; } else existed = true; - return make_error_code(errc::success); + return success; } error_code rename(const Twine &from, const Twine &to) { @@ -210,7 +210,7 @@ error_code rename(const Twine &from, const Twine &to) { if (::rename(f.begin(), t.begin()) == -1) return error_code(errno, system_category()); - return make_error_code(errc::success); + return success; } error_code resize_file(const Twine &path, uint64_t size) { @@ -220,7 +220,7 @@ error_code resize_file(const Twine &path, uint64_t size) { if (::truncate(p.begin(), size) == -1) return error_code(errno, system_category()); - return make_error_code(errc::success); + return success; } error_code exists(const Twine &path, bool &result) { @@ -229,13 +229,13 @@ error_code exists(const Twine &path, bool &result) { struct stat status; if (::stat(p.begin(), &status) == -1) { - if (errno != ENOENT) + if (errno != errc::no_such_file_or_directory) return error_code(errno, system_category()); result = false; } else result = true; - return make_error_code(errc::success); + return success; } error_code equivalent(const Twine &A, const Twine &B, bool &result) { @@ -260,7 +260,7 @@ error_code equivalent(const Twine &A, const Twine &B, bool &result) { stat_a.st_ino == stat_b.st_ino; } - return make_error_code(errc::success); + return success; } error_code file_size(const Twine &path, uint64_t &result) { @@ -271,10 +271,10 @@ error_code file_size(const Twine &path, uint64_t &result) { if (::stat(p.begin(), &status) == -1) return error_code(errno, system_category()); if (!S_ISREG(status.st_mode)) - return error_code(EPERM, system_category()); + return make_error_code(errc::operation_not_permitted); result = status.st_size; - return make_error_code(errc::success); + return success; } error_code status(const Twine &path, file_status &result) { @@ -359,10 +359,10 @@ rety_open_create: int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); if (RandomFD == -1) { // If the file existed, try again, otherwise, error. - if (errno == EEXIST) + if (errno == errc::file_exists) goto retry_random_path; // The path prefix doesn't exist. - if (errno == ENOENT) { + if (errno == errc::no_such_file_or_directory) { StringRef p(RandomPath.begin(), RandomPath.size()); SmallString<64> dir_to_create; for (path::const_iterator i = path::begin(p), @@ -375,7 +375,7 @@ rety_open_create: if (i->size() > 2 && (*i)[0] == '/' && (*i)[1] == '/' && (*i)[2] != '/') - return error_code(ENOENT, system_category()); + return make_error_code(errc::no_such_file_or_directory); if (::mkdir(dir_to_create.c_str(), 0700) == -1) return error_code(errno, system_category()); } @@ -385,7 +385,7 @@ rety_open_create: return error_code(errno, system_category()); } - // Make the path absolute. + // Make the path absolute. char real_path_buff[PATH_MAX + 1]; if (realpath(RandomPath.c_str(), real_path_buff) == NULL) { ::close(RandomFD); @@ -398,7 +398,7 @@ rety_open_create: result_path.append(d.begin(), d.end()); result_fd = RandomFD; - return make_error_code(errc::success); + return success; } } // end namespace fs diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc index 7d9421ac768..f6f53714b06 100644 --- a/lib/Support/Windows/PathV2.inc +++ b/lib/Support/Windows/PathV2.inc @@ -48,7 +48,7 @@ namespace { utf16.begin(), 0); if (len == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); utf16.reserve(len + 1); utf16.set_size(len); @@ -58,13 +58,13 @@ namespace { utf16.begin(), utf16.size()); if (len == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); // Make utf16 null terminated. utf16.push_back(0); utf16.pop_back(); - return make_error_code(errc::success); + return success; } error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, @@ -76,7 +76,7 @@ namespace { NULL, NULL); if (len == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); utf8.reserve(len); utf8.set_size(len); @@ -88,13 +88,13 @@ namespace { NULL, NULL); if (len == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); // Make utf8 null terminated. utf8.push_back(0); utf8.pop_back(); - return make_error_code(errc::success); + return success; } error_code TempDir(SmallVectorImpl &result) { @@ -102,7 +102,7 @@ namespace { DWORD len = ::GetTempPathW(result.capacity(), result.begin()); if (len == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); if (len > result.capacity()) { result.reserve(len); @@ -110,7 +110,7 @@ namespace { } result.set_size(len); - return make_error_code(errc::success); + return success; } struct AutoCryptoProvider { @@ -136,7 +136,7 @@ retry_cur_dir: // A zero return value indicates a failure other than insufficient space. if (len == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); // If there's insufficient space, the len returned is larger than the len // given. @@ -167,9 +167,9 @@ retry_cur_dir: result.data(), result.size(), NULL, NULL); if (len == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); - return make_error_code(errc::success); + return success; } } // end namespace path @@ -194,9 +194,9 @@ error_code copy_file(const Twine &from, const Twine &to, copy_option copt) { copt != copy_option::overwrite_if_exists); if (res == 0) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); - return make_error_code(errc::success); + return success; } error_code create_directory(const Twine &path, bool &existed) { @@ -208,15 +208,15 @@ error_code create_directory(const Twine &path, bool &existed) { return ec; if (!::CreateDirectoryW(path_utf16.begin(), NULL)) { - error_code ec = make_error_code(windows_error(::GetLastError())); - if (ec == make_error_code(windows_error::already_exists)) + error_code ec = windows_error(::GetLastError()); + if (ec == windows_error::already_exists) existed = true; else return ec; } else existed = false; - return make_error_code(errc::success); + return success; } error_code create_hard_link(const Twine &to, const Twine &from) { @@ -233,9 +233,9 @@ error_code create_hard_link(const Twine &to, const Twine &from) { if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec; if (!::CreateHardLinkW(wide_from.begin(), wide_to.begin(), NULL)) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); - return make_error_code(errc::success); + return success; } error_code create_symlink(const Twine &to, const Twine &from) { @@ -256,9 +256,9 @@ error_code create_symlink(const Twine &to, const Twine &from) { if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec; if (!create_symbolic_link_api(wide_from.begin(), wide_to.begin(), 0)) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); - return make_error_code(errc::success); + return success; } error_code remove(const Twine &path, bool &existed) { @@ -270,14 +270,14 @@ error_code remove(const Twine &path, bool &existed) { return ec; if (!::DeleteFileW(path_utf16.begin())) { - error_code ec = make_error_code(windows_error(::GetLastError())); - if (ec != make_error_code(windows_error::file_not_found)) + error_code ec = windows_error(::GetLastError()); + if (ec != windows_error::file_not_found) return ec; existed = false; } else existed = true; - return make_error_code(errc::success); + return success; } error_code rename(const Twine &from, const Twine &to) { @@ -294,9 +294,9 @@ error_code rename(const Twine &from, const Twine &to) { if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec; if (!::MoveFileW(wide_from.begin(), wide_to.begin())) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); - return make_error_code(errc::success); + return success; } error_code resize_file(const Twine &path, uint64_t size) { @@ -332,13 +332,13 @@ error_code exists(const Twine &path, bool &result) { if (attributes == INVALID_FILE_ATTRIBUTES) { // See if the file didn't actually exist. error_code ec = make_error_code(windows_error(::GetLastError())); - if (ec != error_code(windows_error::file_not_found) && - ec != error_code(windows_error::path_not_found)) + if (ec != windows_error::file_not_found && + ec != windows_error::path_not_found) return ec; result = false; } else result = true; - return make_error_code(errc::success); + return success; } error_code equivalent(const Twine &A, const Twine &B, bool &result) { @@ -375,21 +375,21 @@ error_code equivalent(const Twine &A, const Twine &B, bool &result) { // If both handles are invalid, it's an error. if (HandleA == INVALID_HANDLE_VALUE && HandleB == INVALID_HANDLE_VALUE) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); // If only one is invalid, it's false. if (HandleA == INVALID_HANDLE_VALUE && HandleB == INVALID_HANDLE_VALUE) { result = false; - return make_error_code(errc::success); + return success; } // Get file information. BY_HANDLE_FILE_INFORMATION InfoA, InfoB; if (!::GetFileInformationByHandle(HandleA, &InfoA)) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); if (!::GetFileInformationByHandle(HandleB, &InfoB)) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); // See if it's all the same. result = @@ -403,7 +403,7 @@ error_code equivalent(const Twine &A, const Twine &B, bool &result) { InfoA.ftLastWriteTime.dwHighDateTime == InfoB.ftLastWriteTime.dwHighDateTime; - return make_error_code(errc::success); + return success; } error_code file_size(const Twine &path, uint64_t &result) { @@ -418,13 +418,13 @@ error_code file_size(const Twine &path, uint64_t &result) { if (!::GetFileAttributesExW(path_utf16.begin(), ::GetFileExInfoStandard, &FileData)) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); result = (uint64_t(FileData.nFileSizeHigh) << (sizeof(FileData.nFileSizeLow) * 8)) + FileData.nFileSizeLow; - return make_error_code(errc::success); + return success; } error_code status(const Twine &path, file_status &result) { @@ -504,13 +504,12 @@ error_code unique_file(const Twine &model, int &result_fd, // Get a Crypto Provider for CryptGenRandom. AutoCryptoProvider CryptoProvider; - BOOL success = ::CryptAcquireContextW(&CryptoProvider.CryptoProvider, - NULL, - NULL, - PROV_RSA_FULL, - 0); - if (!success) - return make_error_code(windows_error(::GetLastError())); + if (!::CryptAcquireContextW(&CryptoProvider.CryptoProvider, + NULL, + NULL, + PROV_RSA_FULL, + 0)) + return windows_error(::GetLastError()); retry_random_path: random_path_utf16.set_size(0); @@ -520,7 +519,7 @@ retry_random_path: if (*i == L'%') { BYTE val = 0; if (!::CryptGenRandom(CryptoProvider, 1, &val)) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); random_path_utf16.push_back("0123456789abcdef"[val & 15]); } else @@ -543,11 +542,11 @@ retry_create_file: NULL); if (TempFileHandle == INVALID_HANDLE_VALUE) { // If the file existed, try again, otherwise, error. - error_code ec = make_error_code(windows_error(::GetLastError())); - if (ec == error_code(windows_error::file_exists)) + error_code ec = windows_error(::GetLastError()); + if (ec == windows_error::file_exists) goto retry_random_path; // Check for non-existing parent directories. - if (ec == error_code(windows_error::path_not_found)) { + if (ec == windows_error::path_not_found) { // Create the directories using result_path as temp storage. if (error_code ec = UTF16ToUTF8(random_path_utf16.begin(), random_path_utf16.size(), result_path)) @@ -570,7 +569,7 @@ retry_create_file: // Create the directory. if (!::CreateDirectoryW(dir_to_create_utf16.begin(), NULL)) - return make_error_code(windows_error(::GetLastError())); + return windows_error(::GetLastError()); } } goto retry_create_file; @@ -593,11 +592,11 @@ retry_create_file: ::DeleteFileW(random_path_utf16.begin()); // MSDN doesn't say anything about _open_osfhandle setting errno or // GetLastError(), so just return invalid_handle. - return make_error_code(windows_error::invalid_handle); + return windows_error::invalid_handle; } result_fd = fd; - return make_error_code(errc::success); + return success; } } // end namespace fs } // end namespace sys