MCPcopy Create free account
hub / github.com/MhmRdd/NoHello / GetOpenFds

Function GetOpenFds

module/src/main/cpp/external/fdutils/fd_utils.cpp:300–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298static int ParseFd(dirent* dir_entry, int dir_fd);
299
300std::unique_ptr<std::set<int>> GetOpenFds(fail_fn_t fail_fn) {
301 DIR* proc_fd_dir = opendir(kFdPath);
302 if (proc_fd_dir == nullptr) {
303 fail_fn(android::base::StringPrintf("Unable to open directory %s: %s",
304 kFdPath,
305 strerror(errno)));
306 return nullptr; // Return nullptr on error
307 }
308 auto result = std::make_unique<std::set<int>>();
309 int dir_fd = dirfd(proc_fd_dir);
310 dirent* dir_entry;
311 while ((dir_entry = readdir(proc_fd_dir)) != nullptr) {
312 const int fd = ParseFd(dir_entry, dir_fd);
313 if (fd == -1) {
314 continue;
315 }
316
317 result->insert(fd);
318 }
319 if (closedir(proc_fd_dir) == -1) {
320 fail_fn(android::base::StringPrintf("Unable to close directory: %s", strerror(errno)));
321 }
322 return result;
323}
324
325static int ParseFd(dirent* dir_entry, int dir_fd) {
326 char* end;

Callers 1

preSpecializeMethod · 0.85

Calls 2

StringPrintfFunction · 0.85
ParseFdFunction · 0.85

Tested by

no test coverage detected