/* * SPDsoft 2001 * stat * Thu Apr 19 11:16:13 DST 2001 */ #include #include #include #include #include #include #include #include #include #include char *app; #define PATH_SEP '/' void usage(void) { fprintf(stderr,"Use: %s [-s] filename(s)\n",app); fprintf(stderr,"-s: Sun /var/sadm/install/contents mode\n"); exit(1); } main( int argc, char **argv) { int opt; struct stat sbp; int f; int isdevice=0; int islink=0; struct passwd *pw; struct group *gr; char *name; char *gname; int error=0; int sun_mode=0; int l; int sum; FILE *F; char b[MAXPATHLEN]; if ( NULL != (app = strrchr(argv[0], PATH_SEP))) app++; else app = argv[0]; while ( (opt=getopt(argc,argv,"s")) != EOF ) { switch(opt) { case 's': sun_mode=1; break; default: usage(); break; } } if ((argc-optind)<1) usage(); for( f=optind; fpw_name; if (( gr=getgrgid(sbp.st_gid))==NULL) gname="???"; else gname=gr->gr_name; if (!sun_mode) { printf(" Size: %ld\n", sbp.st_size); printf(" Mode: %0.4o\n",sbp.st_mode & 0xfff); printf(" Uid: %d %s\n",sbp.st_uid, name); printf(" Gid: %d %s\n",sbp.st_uid, gname); printf("Device: %d,%d\t", (sbp.st_dev>>8) & 0xff, sbp.st_dev & 0xff); printf("Inode: %d\tLinks: %d\n", sbp.st_ino, sbp.st_nlink); if (isdevice) { printf("Device type:%d,%d\n", (sbp.st_rdev>>8) & 0xff, sbp.st_rdev & 0xff ); } if ((sbp.st_mode & S_ISUID )== S_ISUID ) printf("Set-user-ID\n"); if ((sbp.st_mode & S_ISGID )== S_ISGID ) printf("Set-group-ID\n"); if ((sbp.st_mode & S_ISVTX )== S_ISVTX ) printf("Save swapped text after use\n"); printf("Last access: %d %s", sbp.st_atime, asctime(localtime(&sbp.st_atime ))); printf("Last modification: %d %s", sbp.st_mtime, asctime(localtime(&sbp.st_mtime ))); printf("Last status change: %d %s", sbp.st_ctime, asctime(localtime(&sbp.st_ctime ))); } else { sum=0; switch (sbp.st_mode & S_IFMT) { case S_IFLNK: printf("NA\n",b); break; case S_IFREG: sprintf(b,"sum %s", argv[f]); if ( NULL != (F=popen(b,"r"))) { fscanf(F,"%d",&sum); pclose(F); } else perror("popen"); default: printf("%0.4o %s %s %ld %d %d NA\n", sbp.st_mode & 0xfff, name,gname, sbp.st_size, sum, sbp.st_mtime); break; } } } } exit(error); }