Mercurial > minori
diff dep/animia/src/linux.cpp @ 62:4c6dd5999b39
*: update
1. updated animia
2. use widestrings for filesystem on Windows
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 06:16:06 -0400 |
parents | 6ff7aabeb9d7 |
children | 1ce00c1c8ddc |
line wrap: on
line diff
--- a/dep/animia/src/linux.cpp Fri Sep 29 15:52:31 2023 -0400 +++ b/dep/animia/src/linux.cpp Sun Oct 01 06:16:06 2023 -0400 @@ -1,14 +1,14 @@ -#include <string> -#include <vector> +#include <algorithm> +#include <fcntl.h> +#include <filesystem> #include <fstream> -#include <filesystem> -#include <unordered_map> #include <iostream> #include <sstream> -#include <unistd.h> +#include <string> #include <sys/stat.h> -#include <fcntl.h> -#include <algorithm> +#include <unistd.h> +#include <unordered_map> +#include <vector> #define PROC_LOCATION "/proc" @@ -33,6 +33,7 @@ std::ifstream t(path); std::stringstream buf; buf << t.rdbuf(); + std::string str = buf.str(); str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); return str; @@ -79,17 +80,16 @@ /* get filename size */ int size = get_size_of_link(dir.path().string()); /* allocate buffer */ - char* buf = (char*)calloc(size, sizeof(char)); - //std::string buf('\0', size); + std::string buf(size, '\0'); + // std::string buf('\0', size); /* read filename to buffer */ - int r = readlink(dir.path().c_str(), buf, size); + int r = readlink(dir.path().c_str(), &buf.front(), buf.length()); if (r < 0) continue; if (!is_regular_file(buf)) continue; ret.push_back(buf); - free(buf); } } catch (std::filesystem::filesystem_error const& ex) { if (ex.code().value() != 13) // 13 == permissions error, common with /proc, ignore @@ -101,9 +101,9 @@ std::unordered_map<int, std::vector<std::string>> get_all_open_files() { std::unordered_map<int, std::vector<std::string>> map; std::vector<int> pids = get_all_pids(); - for (int i: pids) + for (int i : pids) map[i] = get_open_files(i); return map; } -} +} // namespace Animia::Linux