The problem with std::vector is that the role is not clear.
Impl. aside, libwy
https://sourceforge.net/projects/cscall/files/latest/download
clearly defines Array<T> as a wrapper of malloc(2) or the like.
This is lastly added example a_sysinfo.cpp (collect and dump system information)
#include <Wy.stdio.h>
#include <Wy.unistd.h>
#include <Wy.time.h>
#include <sys/utsname.h>
using namespace Wy;
String getfile(const char* fname)
{
Errno r;
String str;
cout << "---------------- Dump file: " << fname << " -----------------" WY_ENDL;
if((r=Wy::access(fname,F_OK))!=Ok) { // showcase, this check is not necessary
return "File (" + String(fname) + ") reading error: " + wrd(r) + WY_ENDL;
}
RegFile regf(fname,O_RDONLY); // may be virtual files (file size=0),
RdBuf strm(regf); // get_whole_regfile(..) won't work
for(;strm.is_eof()==false;) {
if((r=strm.append_read(str))!=Ok) {
WY_THROW(r);
}
if(str.size()>1000000) {
WY_THROW( Errno(EFBIG) ); // file size > 1-mega bytes
}
}
return str;
};
void dump_sysinfo() {
Errno r;
String str;
cout << "hostname: " << Wy::gethostname() << WY_ENDL;
{
struct utsname buf;
if(::uname(&buf)!=0) {
WY_THROW( Errno(errno) );
}
cout << WY_ENDL;
cout << "---------------- Dump struct utsname -----------------" WY_ENDL;
cout << "sysname : " << buf.sysname << WY_ENDL;
cout << "nodename: " << buf.nodename << WY_ENDL;
cout << "release : " << buf.release << WY_ENDL;
cout << "version : " << buf.version << WY_ENDL;
cout << "machine : " << buf.machine << WY_ENDL;
}
cout << WY_ENDL;
cout << "ttyname(cerr): " << ttyname(cerr) << WY_ENDL;
cout << "ttyname(cin): " << ttyname(cin) << WY_ENDL;
cout << "ttyname(cout): " << ttyname(cout) << WY_ENDL;
cout << "ctermid(): " << ctermid() << WY_ENDL;
cout << WY_ENDL;
cout << "timezone: " << local_tzname() << WY_ENDL;
cout << WY_ENDL;
cout << "current working directory: " << getcwd() << WY_ENDL;
cout << WY_ENDL;
cout << getfile("/etc/os-release");
cout << WY_ENDL;
cout << getfile("/proc/cpuinfo");
cout << WY_ENDL;
cout << getfile("/proc/version");
cout << WY_ENDL;
cout << getfile("/proc/meminfo");
cout << WY_ENDL;
};
int main(int argc, const char* argv[])
try {
dump_sysinfo();
return 0;
}
catch(const Errno& e) {
cerr << wrd(e) << WY_ENDL;
return e.c_errno();
}
catch(...) {
cerr << "main() caught(...)" WY_ENDL;
throw;
};