# HG changeset patch # User Paper # Date 1701710070 18000 # Node ID d26cd2c00270308b09b25d6615144976c7855d82 # Parent 5be17d636aee68222d3e7b5fda36b98a4059de75 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 diff -r 5be17d636aee -r d26cd2c00270 dep/animia/src/fd/proc.cc --- 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 #include -#ifdef FREEBSD -# include -# include -# include -#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))))