014
02.09.2003, 14:25 Uhr
virtual
Sexiest Bit alive (Operator)
|
Ich hab mal schnell was gebaut :D. Das beweist, daß es ziemlich wurscht ist, was man dem Stat übergibt.
C++: |
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <pwd.h> #include <grp.h> #include <time.h>
int main(int argc, char** argv) { int i, j; struct stat sb; int returncode = EXIT_SUCCESS;
for(i=1; i<argc; ++i) { char p[] = "---------"; struct passwd* pw; struct group* gr;
/* * Fetch information */ if (0 != stat(argv[i], &sb)) { fprintf(stderr, "stat(\"%s\",...) failed: %s (%d)\n", argv[i], strerror(errno), errno); returncode = EXIT_FAILURE; continue; }
/* * Print information */ printf("File information for \"%s\":\n", argv[i]); printf("\tDevice: %d/%d\n", (unsigned)sb.st_dev/256, (unsigned)sb.st_dev%256); printf("\tINode: %ld\n", sb.st_ino); printf("\tType: "); switch (sb.st_mode&S_IFMT) { case S_IFSOCK: puts("socket file"); break; case S_IFLNK: puts("siymbolic link"); break; case S_IFREG: puts("regular file"); break; case S_IFBLK: puts("block device"); break; case S_IFCHR: puts("character device"); break; case S_IFDIR: puts("directory"); break; case S_IFIFO: puts("named pipe"); break; default: puts("*** dont know ***"); break; } /* Just a golf joke */ for(j=0; j<12; ++j) p[8-(j<9?j:(j-9)*3)] += (sb.st_mode&1<<j?(j<9?69+(j%3?((j+1)%3?5:0):6):p[8-3*(j-9)]!='-'?(j==9?-4:-5):(j==9?39:38)):0); printf("\tMode: %o (%s)\n", 07777&sb.st_mode, p); printf("\tNumber of Links: %d\n", sb.st_nlink); pw = getpwuid(sb.st_uid); printf("\tOwning user: %s (%d)\n", pw? pw->pw_name:"???", sb.st_uid); gr = getgrgid(sb.st_gid); printf("\tOwning group: %s (%d)\n", gr? gr->gr_name:"???", sb.st_gid); if ((sb.st_mode&S_IFMT)==S_IFCHR || (sb.st_mode&S_IFMT)==S_IFBLK) { printf("\tDevice type: %d/%d\n", (unsigned)sb.st_rdev/256, (unsigned)sb.st_rdev%256); } printf("\tSize (bytes): %ld\n", sb.st_size); printf("\tBytes per block: %ld\n", sb.st_blksize); printf("\tSize (blocks): %ld\n", sb.st_blocks/(sb.st_blksize/512)); printf("\tAccess time: %s", ctime(&sb.st_atime)); printf("\tModify time: %s", ctime(&sb.st_mtime)); printf("\tCreation time: %s", ctime(&sb.st_ctime)); } return returncode; }
|
-- Gruß, virtual Quote of the Month Ich eß' nur was ein Gesicht hat (Creme 21) Dieser Post wurde am 02.09.2003 um 14:31 Uhr von urform editiert. |