diff options
Diffstat (limited to 'lib/Support/Unix/PathV2.inc')
-rw-r--r-- | lib/Support/Unix/PathV2.inc | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc index bbbc344661be..edb101efb0f6 100644 --- a/lib/Support/Unix/PathV2.inc +++ b/lib/Support/Unix/PathV2.inc @@ -46,6 +46,11 @@ #include <limits.h> #endif +// For GNU Hurd +#if defined(__GNU__) && !defined(PATH_MAX) +# define PATH_MAX 4096 +#endif + using namespace llvm; namespace { @@ -87,7 +92,7 @@ namespace { result.clear(); StringRef d(dir); result.append(d.begin(), d.end()); - return success; + return error_code::success(); } } @@ -96,7 +101,12 @@ namespace sys { namespace fs { error_code current_path(SmallVectorImpl<char> &result) { +#ifdef MAXPATHLEN result.reserve(MAXPATHLEN); +#else +// For GNU Hurd + result.reserve(1024); +#endif while (true) { if (::getcwd(result.data(), result.capacity()) == 0) { @@ -110,7 +120,7 @@ error_code current_path(SmallVectorImpl<char> &result) { } result.set_size(strlen(result.data())); - return success; + return error_code::success(); } error_code copy_file(const Twine &from, const Twine &to, copy_option copt) { @@ -169,7 +179,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 success; + return error_code::success(); } error_code create_directory(const Twine &path, bool &existed) { @@ -183,7 +193,7 @@ error_code create_directory(const Twine &path, bool &existed) { } else existed = false; - return success; + return error_code::success(); } error_code create_hard_link(const Twine &to, const Twine &from) { @@ -196,7 +206,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 success; + return error_code::success(); } error_code create_symlink(const Twine &to, const Twine &from) { @@ -209,7 +219,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 success; + return error_code::success(); } error_code remove(const Twine &path, bool &existed) { @@ -223,7 +233,7 @@ error_code remove(const Twine &path, bool &existed) { } else existed = true; - return success; + return error_code::success(); } error_code rename(const Twine &from, const Twine &to) { @@ -245,7 +255,7 @@ error_code rename(const Twine &from, const Twine &to) { return error_code(errno, system_category()); } - return success; + return error_code::success(); } error_code resize_file(const Twine &path, uint64_t size) { @@ -255,7 +265,7 @@ error_code resize_file(const Twine &path, uint64_t size) { if (::truncate(p.begin(), size) == -1) return error_code(errno, system_category()); - return success; + return error_code::success(); } error_code exists(const Twine &path, bool &result) { @@ -270,32 +280,21 @@ error_code exists(const Twine &path, bool &result) { } else result = true; - return success; + return error_code::success(); } -error_code equivalent(const Twine &A, const Twine &B, bool &result) { - // Get arguments. - SmallString<128> a_storage; - SmallString<128> b_storage; - StringRef a = A.toNullTerminatedStringRef(a_storage); - StringRef b = B.toNullTerminatedStringRef(b_storage); - - struct stat stat_a, stat_b; - int error_b = ::stat(b.begin(), &stat_b); - int error_a = ::stat(a.begin(), &stat_a); - - // If both are invalid, it's an error. If only one is, the result is false. - if (error_a != 0 || error_b != 0) { - if (error_a == error_b) - return error_code(errno, system_category()); - result = false; - } else { - result = - stat_a.st_dev == stat_b.st_dev && - stat_a.st_ino == stat_b.st_ino; - } +bool equivalent(file_status A, file_status B) { + assert(status_known(A) && status_known(B)); + return A.st_dev == B.st_dev && + A.st_ino == B.st_ino; +} - return success; +error_code equivalent(const Twine &A, const Twine &B, bool &result) { + file_status fsA, fsB; + if (error_code ec = status(A, fsA)) return ec; + if (error_code ec = status(B, fsB)) return ec; + result = equivalent(fsA, fsB); + return error_code::success(); } error_code file_size(const Twine &path, uint64_t &result) { @@ -309,7 +308,7 @@ error_code file_size(const Twine &path, uint64_t &result) { return make_error_code(errc::operation_not_permitted); result = status.st_size; - return success; + return error_code::success(); } error_code status(const Twine &path, file_status &result) { @@ -341,7 +340,10 @@ error_code status(const Twine &path, file_status &result) { else result = file_status(file_type::type_unknown); - return success; + result.st_dev = status.st_dev; + result.st_ino = status.st_ino; + + return error_code::success(); } error_code unique_file(const Twine &model, int &result_fd, @@ -436,10 +438,11 @@ rety_open_create: result_path.append(d.begin(), d.end()); result_fd = RandomFD; - return success; + return error_code::success(); } -error_code directory_iterator_construct(directory_iterator &it, StringRef path){ +error_code detail::directory_iterator_construct(detail::DirIterState &it, + StringRef path){ SmallString<128> path_null(path); DIR *directory = ::opendir(path_null.c_str()); if (directory == 0) @@ -452,15 +455,15 @@ error_code directory_iterator_construct(directory_iterator &it, StringRef path){ return directory_iterator_increment(it); } -error_code directory_iterator_destruct(directory_iterator& it) { +error_code detail::directory_iterator_destruct(detail::DirIterState &it) { if (it.IterationHandle) ::closedir(reinterpret_cast<DIR *>(it.IterationHandle)); it.IterationHandle = 0; it.CurrentEntry = directory_entry(); - return success; + return error_code::success(); } -error_code directory_iterator_increment(directory_iterator& it) { +error_code detail::directory_iterator_increment(detail::DirIterState &it) { errno = 0; dirent *cur_dir = ::readdir(reinterpret_cast<DIR *>(it.IterationHandle)); if (cur_dir == 0 && errno != 0) { @@ -474,7 +477,7 @@ error_code directory_iterator_increment(directory_iterator& it) { } else return directory_iterator_destruct(it); - return success; + return error_code::success(); } error_code get_magic(const Twine &path, uint32_t len, @@ -505,7 +508,7 @@ error_code get_magic(const Twine &path, uint32_t len, } std::fclose(file); result.set_size(len); - return success; + return error_code::success(); } } // end namespace fs |