Skip to content

Instantly share code, notes, and snippets.

@gsdayton98
Created June 9, 2021 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsdayton98/d2eef56ab871b35b8ceb6bb32e1945a9 to your computer and use it in GitHub Desktop.
Save gsdayton98/d2eef56ab871b35b8ceb6bb32e1945a9 to your computer and use it in GitHub Desktop.
Print struct state
#include <iomanip>
#include <iostream>
#include <sys/stat.h>
std::ostream& operator<<(std::ostream& gozouta, const struct stat& st) {
gozouta << "File stat" << std::endl;
gozouta << "device: " << st.st_dev << " rdev: " << st.st_rdev << std::endl;
gozouta << "mode: " << std::oct << std::setfill('0') << std::setw(4) << st.st_mode << std::endl;
gozouta << "nlinks: " << std::dec << st.st_nlink << std::endl;
gozouta << "inode: " << std::dec << st.st_ino << std::endl;
gozouta << "u/gid: " << std::dec << st.st_uid << ":" << st.st_gid<< std::endl;
gozouta << "atime: " << st.st_atimespec << std::endl;
gozouta << "mtime: " << st.st_mtimespec << std::endl;
gozouta << "ctime: " << st.st_ctimespec << std::endl;
gozouta << "btime: " << st.st_birthtimespec << std::endl;
gozouta << "filesize: " << st.st_size << " bytes " << st.st_blocks << " blocks" << std::endl;
gozouta << "blksize: " << std::dec << st.st_blksize << " bytes" << std::endl;
gozouta << "flags: " << std::hex << std::setfill('0') << std::setw(8) << st.st_flags << std::endl;
gozouta << "generation: " << std::dec << st.st_gen << std::endl;
return gozouta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment