[PATCH] D54677: [hurd] Fix unconditional use of PATH_MAX

Eric Fiselier via Phabricator reviews at reviews.llvm.org
Mon Dec 10 09:52:40 PST 2018


EricWF added inline comments.


================
Comment at: src/filesystem/operations.cpp:535
+  char *buff;
+  if ((buff = ::realpath(p.c_str(), NULL)) == nullptr)
+    return err.report(capture_errno());
----------------
s/`NULL`/`nullptr`/


================
Comment at: src/filesystem/operations.cpp:536
+  if ((buff = ::realpath(p.c_str(), NULL)) == nullptr)
+    return err.report(capture_errno());
+  path ret = {buff};
----------------
I think we can RAII this up like:

```
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()};
```


================
Comment at: src/filesystem/operations.cpp:1087
   ErrorHandler<path> err("read_symlink", ec, &p);
+  ::ssize_t ret;
 
----------------
I would like to see these two paths merged even further. How about:

```

path __read_symlink(const path& p, error_code* ec) {
  ErrorHandler<path> err("read_symlink", ec, &p);
#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());
  }
  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 <= size, "TODO");
  _LIBCPP_ASSERT(ret > 0, "TODO");
  buff[ret] = 0;
  return {buff.get()};
}
```


================
Comment at: src/filesystem/operations.cpp:1101
+#else
+  struct stat sb;
+  if (::lstat(p.c_str(), &sb) == -1) {
----------------
Use the `StatT` typedef we already have.


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54677/new/

https://reviews.llvm.org/D54677





More information about the libcxx-commits mailing list