485 |
485 |
486 /* Make a char of 512 empty bytes */ |
486 /* Make a char of 512 empty bytes */ |
487 char empty[512]; |
487 char empty[512]; |
488 memset(&empty[0], 0, sizeof(empty)); |
488 memset(&empty[0], 0, sizeof(empty)); |
489 |
489 |
490 while (!feof(f)) { |
490 for (;;) { // Note: feof() always returns 'false' after 'fseek()'. Cool, isn't it? |
491 pos += fread(&th, 1, 512, f); |
491 size_t num_bytes_read = fread(&th, 1, 512, f); |
|
492 if (num_bytes_read != 512) break; |
|
493 pos += num_bytes_read; |
492 |
494 |
493 /* Check if we have the new tar-format (ustar) or the old one (a lot of zeros after 'link' field) */ |
495 /* Check if we have the new tar-format (ustar) or the old one (a lot of zeros after 'link' field) */ |
494 if (strncmp(th.magic, "ustar", 5) != 0 && memcmp(&th.magic, &empty[0], 512 - offsetof(TarHeader, magic)) != 0) { |
496 if (strncmp(th.magic, "ustar", 5) != 0 && memcmp(&th.magic, &empty[0], 512 - offsetof(TarHeader, magic)) != 0) { |
495 /* If we have only zeros in the block, it can be an end-of-file indicator */ |
497 /* If we have only zeros in the block, it can be an end-of-file indicator */ |
496 if (memcmp(&th, &empty[0], 512) == 0) continue; |
498 if (memcmp(&th, &empty[0], 512) == 0) continue; |