// call lstat on each command line argument as simple example of its use // lstat differs from stat only for symbolic links, where it will get // the information about the link itself instead of the file it links to #include #include #include #include #include void lstat_file(char *pathname); int main(int argc, char *argv[]) { for (int arg = 1; arg < argc; arg++) { lstat_file(argv[arg]); } return 0; } void lstat_file(char *pathname) { printf("stat(\"%s\", &s)\n", pathname); struct stat s; if (lstat(pathname, &s) != 0) { perror(pathname); exit(1); } printf("ino = %10ld # Inode number\n", s.st_ino); printf("mode = %10o # File mode \n", s.st_mode); printf("nlink =%10ld # Link count \n", (long)s.st_nlink); printf("uid = %10u # Owner uid\n", s.st_uid); printf("gid = %10u # Group gid\n", s.st_gid); printf("size = %10ld # File size (bytes)\n", (long)s.st_size); printf("mtime =%10ld # Modification time (seconds since 1/1/70)\n", (long)s.st_mtime); }