Mercurial > minori
diff dep/animia/src/fd/proc.cc @ 181:d26cd2c00270
dep/animia/fd/proc: use constexpr std::string_view for proc location
this is probably a little slower, but it works Well Enough for what we need it for
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 04 Dec 2023 12:14:30 -0500 |
parents | 5be17d636aee |
children | c413e475f496 |
line wrap: on
line diff
--- a/dep/animia/src/fd/proc.cc Mon Dec 04 12:08:29 2023 -0500 +++ b/dep/animia/src/fd/proc.cc Mon Dec 04 12:14:30 2023 -0500 @@ -16,13 +16,7 @@ #include <sys/stat.h> #include <unistd.h> -#ifdef FREEBSD -# include <sys/types.h> -# include <sys/user.h> -# include <libutil.h> -#endif - -#define PROC_LOCATION "/proc" +static constexpr std::string_view PROC_LOCATION = "/proc"; namespace animia::internal::proc { @@ -57,7 +51,7 @@ } static bool AreFlagsOk(pid_t pid, int fd) { - const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fdinfo/" + std::to_string(fd); + const std::string path = std::string(PROC_LOCATION) + "/" + std::to_string(pid) + "/fdinfo/" + std::to_string(fd); std::ifstream file(path.c_str()); if (!file) @@ -94,7 +88,7 @@ static std::string GetProcessName(pid_t pid) { std::string result; - const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/comm"; + const std::string path = std::string(PROC_LOCATION) + "/" + std::to_string(pid) + "/comm"; if (!util::ReadFile(path, result)) return ""; @@ -106,7 +100,7 @@ bool ProcFdTools::EnumerateOpenProcesses(process_proc_t process_proc) { bool success = false; - for (const auto& dir : GetAllFilesInDir(PROC_LOCATION)) { + for (const auto& dir : GetAllFilesInDir(std::string(PROC_LOCATION))) { pid_t pid; try { pid = std::stoul(Basename(dir)); @@ -125,7 +119,7 @@ return false; for (const auto& pid : pids) { - const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fd"; + const std::string path = std::string(PROC_LOCATION) + "/" + std::to_string(pid) + "/fd"; for (const auto& dir : GetAllFilesInDir(path)) { if (!AreFlagsOk(pid, std::stoi(Basename(dir))))