mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
modules/console: Add a proc cmd.
This commit is contained in:
parent
2cc7831770
commit
e16eefb8fb
1 changed files with 52 additions and 0 deletions
|
@ -628,6 +628,58 @@ console_cmd__date(opt &out, const string_view &line)
|
|||
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
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue