Mercurial > minori
comparison dep/animia/src/fd/linux.cc @ 150:ffa535b6d630
*: avoid usage of std::[pair,tuple]
https://arne-mertz.de/2017/03/smelly-pair-tuple/
it's better to use real structures and such where variables are easily known...
also apparently using [] on structs is actually valid? I had no idea.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 14 Nov 2023 16:27:33 -0500 |
parents | aa4df5a84338 |
children | 54744a48a7d7 |
comparison
equal
deleted
inserted
replaced
149:e41505d24733 | 150:ffa535b6d630 |
---|---|
122 | 122 |
123 result.erase(std::remove(result.begin(), result.end(), '\n'), result.end()); | 123 result.erase(std::remove(result.begin(), result.end(), '\n'), result.end()); |
124 return true; | 124 return true; |
125 } | 125 } |
126 | 126 |
127 bool LinuxFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::pair<pid_t, std::string>>& files) { | 127 bool LinuxFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<OpenFile>& files) { |
128 for (const auto& pid : pids) { | 128 for (const auto& pid : pids) { |
129 const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fd"; | 129 const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fd"; |
130 | 130 |
131 for (const auto& dir : GetAllFilesInDir(path)) { | 131 for (const auto& dir : GetAllFilesInDir(path)) { |
132 if (!AreFlagsOk(pid, std::stoi(Basename(dir)))) | 132 if (!AreFlagsOk(pid, std::stoi(Basename(dir)))) |
135 std::string name = GetFilenameFromFd(dir); | 135 std::string name = GetFilenameFromFd(dir); |
136 | 136 |
137 if (!IsRegularFile(name)) | 137 if (!IsRegularFile(name)) |
138 continue; | 138 continue; |
139 | 139 |
140 files.push_back({pid, name}); | 140 OpenFile file; |
141 file.pid = pid; | |
142 file.path = name; | |
143 | |
144 files.push_back(file); | |
141 } | 145 } |
142 } | 146 } |
143 return true; | 147 return true; |
144 } | 148 } |
145 | 149 |