From 3c16be834750bffd48f80d1b60910b38ee65a3bf Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Fri, 21 Jan 2022 07:48:14 -0800 Subject: [PATCH] Replace deprecated `readdir64_r` Plain `readdir` is preferred and while not (yet) specified in POSIX it is thread-safe for different directory streams in popular implementations. PiperOrigin-RevId: 423321528 Change-Id: I4e1e842f338ff7d690c36e7f699b2f3637609524 --- sandboxed_api/util/fileops.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/sandboxed_api/util/fileops.cc b/sandboxed_api/util/fileops.cc index a992de7..1537281 100644 --- a/sandboxed_api/util/fileops.cc +++ b/sandboxed_api/util/fileops.cc @@ -205,16 +205,9 @@ bool ListDirectoryEntries(const std::string& directory, return false; } - struct dirent64* entry{}; errno = 0; - int bufferlen = - std::max(offsetof(struct dirent64, d_name) + - pathconf(directory.c_str(), _PC_NAME_MAX) + 1, - sizeof(struct dirent64)); - std::unique_ptr dirent_buffer{ - static_cast(malloc(bufferlen)), - [](struct dirent64* p) { free(p); }}; - while (readdir64_r(dir.get(), dirent_buffer.get(), &entry) == 0 && entry) { + struct dirent* entry; + while ((entry = readdir(dir.get())) != nullptr) { const std::string name(entry->d_name); if (name != "." && name != "..") { entries->push_back(name);