Code :
#include <stdio.h> #include <stdlib.h> #include <string.h> struct tarheader { char filename[100]; char mode[8]; char uid[8]; char gid[8]; char size[12]; char last[12]; char cksum[8]; char typeflag; char linkname[100]; char ustar[8]; char uname[32]; char gname[32]; char devicemajor[8]; char deviceminor[8]; char prefix[155]; char padding[12]; } ; void listContent(FILE * f) { struct tarheader h; while ( fread(&h, sizeof(struct tarheader), 1, f) != 0 ) { /* Blague de barbu : les numeriques sont codes en octal [:petrus75] */ long size = strtol(h.size, NULL, 8); /* chaque bloc pese 512 bytes tout rond, a prendre en compte avant lecture du fichier suivant */ long padding = 512-size%512; fseek(f, size + padding, SEEK_CUR); } } int main(int argc, char **argv) { if ( argc == 2 ) { FILE * tarfile = fopen(argv[1], "rb" ); if ( tarfile ) { listContent(tarfile); fclose(tarfile); } else { fprintf(stderr, "Unable to open '%s'\n", argv[1]); return EXIT_FAILURE; } } else { fprintf(stderr, "Usage : %s <tarfile>\n",argv[0]); return EXIT_FAILURE; } return EXIT_SUCCESS; }
|