This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit efb254e27448b1c18c124a7320913bce687e59b6 Author: Alexey Serbin <[email protected]> AuthorDate: Wed Sep 16 21:45:19 2020 -0700 [util] update on DirName() on BSD-derived system This is a follow-up to e201c15715834f925624463a7ccac8d59c3464eb. Change-Id: Ic70ea96640d281bda372bd54c7d67bb1a59e0a8b Reviewed-on: http://gerrit.cloudera.org:8080/16467 Tested-by: Kudu Jenkins Reviewed-by: Grant Henke <[email protected]> --- src/kudu/util/path_util.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/kudu/util/path_util.cc b/src/kudu/util/path_util.cc index 54171bf..9875024 100644 --- a/src/kudu/util/path_util.cc +++ b/src/kudu/util/path_util.cc @@ -17,7 +17,7 @@ #include "kudu/util/path_util.h" -// Use the POSIX version of dirname(3). +// Use the POSIX version of basename(3)/dirname(3). #include <libgen.h> #if defined(__APPLE__) @@ -32,7 +32,6 @@ #if defined(__APPLE__) #include <cerrno> -#include <mutex> #endif // defined(__APPLE__) #include <glog/logging.h> @@ -103,12 +102,19 @@ vector<string> SplitPath(const string& path) { } string DirName(const string& path) { - unique_ptr<char[], FreeDeleter> path_copy(strdup(path.c_str())); #if defined(__APPLE__) - static std::mutex lock; - std::lock_guard<std::mutex> l(lock); -#endif // defined(__APPLE__) - return ::dirname(path_copy.get()); + char buf[MAXPATHLEN]; + auto* ret = dirname_r(path.c_str(), buf); + if (PREDICT_FALSE(ret == nullptr)) { + int err = errno; + LOG(FATAL) << strings::Substitute("dirname_r() failed: $0", + ErrnoToString(err)); + } + return ret; +#else + unique_ptr<char[], FreeDeleter> path_copy(strdup(path.c_str())); + return dirname(path_copy.get()); +#endif // #if defined(__APPLE__) ... #else } string BaseName(const string& path) {
