0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

modules/console: Add a proc cmd.

This commit is contained in:
Jason Volk 2018-12-15 16:14:51 -08:00
parent 2cc7831770
commit e16eefb8fb

View file

@ -628,6 +628,58 @@ console_cmd__date(opt &out, const string_view &line)
return true; return true;
} }
//
// proc
//
bool
console_cmd__proc(opt &out, const string_view &line)
{
const params param{line, " ",
{
"filename"
}};
const auto filename
{
param.at("filename", ""_sv)
};
char pathbuf[128];
const string_view path{fmt::sprintf
{
pathbuf, "/proc/self/%s", filename
}};
if(fs::is_dir(path))
{
for(const auto &file : fs::ls(path))
out << file << std::endl;
return true;
}
fs::fd fd
{
path, std::ios::in
};
fs::read_opts opts;
opts.aio = false;
const unique_buffer<mutable_buffer> buf
{
64_KiB
};
const string_view read
{
fs::read(fd, buf, opts)
};
out << read << std::endl;
return true;
}
// //
// mem // mem
// //