Skip to content

Instantly share code, notes, and snippets.

@ProfAvery
Created September 9, 2020 06:45
Show Gist options
  • Save ProfAvery/590490757ffb8a02458999ee4c271e54 to your computer and use it in GitHub Desktop.
Save ProfAvery/590490757ffb8a02458999ee4c271e54 to your computer and use it in GitHub Desktop.
In-class Exercise: Linux Programmer's Manual
#include <cstdlib>
#include <iostream>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
using std::cout;
using std::endl;
int main(int argc, char *argv[])
{
utsname info;
auto ok = uname(&info);
if (ok < 0) {
perror("uname");
return EXIT_FAILURE;
}
cout << argv[0] << " on " << info.sysname << " " << info.release << endl;
for (auto i = 1; i < argc; i++) {
auto filename = argv[i];
struct stat stats;
ok = stat(filename, &stats);
if (ok < 0) {
perror(filename);
return EXIT_FAILURE;
}
cout << filename << ": " << stats.st_size << endl;
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment