Created
September 9, 2020 06:45
-
-
Save ProfAvery/590490757ffb8a02458999ee4c271e54 to your computer and use it in GitHub Desktop.
In-class Exercise: Linux Programmer's Manual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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