Mercurial > minori
changeset 164:99fdf5a90b0f
fd/linux: avoid reading buffers multiple times
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 18 Nov 2023 00:54:29 -0500 |
parents | 44c5e6dd9488 |
children | 8937fb7f2d66 |
files | dep/animia/src/fd/linux.cc |
diffstat | 1 files changed, 7 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/dep/animia/src/fd/linux.cc Sat Nov 18 00:47:40 2023 -0500 +++ b/dep/animia/src/fd/linux.cc Sat Nov 18 00:54:29 2023 -0500 @@ -52,21 +52,16 @@ static bool AreFlagsOk(pid_t pid, int fd) { const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fdinfo/" + std::to_string(fd); - std::stringstream buffer; - { - std::string data; - if (!util::ReadFile(path, data)) - return false; - buffer << data; - } + + std::ifstream file(path.c_str()); + if (!file) + return false; int flags = 0; - for (std::string line; std::getline(buffer, line);) { - /* FIXME: exception handling here!! */ - if (line.rfind("flags:", 0) == 0) { + for (std::string line; std::getline(file, line); ) + if (line.find("flags:", 0) == 0) flags = std::stoi(line.substr(line.find_last_not_of("0123456789") + 1)); - } - } + if (flags & O_WRONLY || flags & O_RDWR) return false; return true;