tar,smemcap: commonalyze checksumming code for tar header
function old new delta chksum_and_xwrite_tar_header - 99 +99 writeheader 280 199 -81 chksum_and_xwrite 102 - -102 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 0/1 up/down: 99/-183) Total: -84 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -29,7 +29,6 @@ struct fileblock {
|
||||
static void writeheader(const char *path, struct stat *sb, int type)
|
||||
{
|
||||
struct tar_header_t header;
|
||||
int i, sum;
|
||||
|
||||
memset(&header, 0, TAR_BLOCK_SIZE);
|
||||
strcpy(header.name, path);
|
||||
@@ -40,20 +39,7 @@ static void writeheader(const char *path, struct stat *sb, int type)
|
||||
sprintf(header.size, "%o", (unsigned)sb->st_size);
|
||||
sprintf(header.mtime, "%llo", sb->st_mtime & 077777777777LL);
|
||||
header.typeflag = type;
|
||||
strcpy(header.magic, "ustar "); /* like GNU tar */
|
||||
|
||||
/* Calculate and store the checksum (the sum of all of the bytes of
|
||||
* the header). The checksum field must be filled with blanks for the
|
||||
* calculation. The checksum field is formatted differently from the
|
||||
* other fields: it has 6 digits, a NUL, then a space -- rather than
|
||||
* digits, followed by a NUL like the other fields... */
|
||||
header.chksum[7] = ' ';
|
||||
sum = ' ' * 7;
|
||||
for (i = 0; i < TAR_BLOCK_SIZE; i++)
|
||||
sum += ((unsigned char*)&header)[i];
|
||||
sprintf(header.chksum, "%06o", sum);
|
||||
|
||||
xwrite(STDOUT_FILENO, &header, TAR_BLOCK_SIZE);
|
||||
chksum_and_xwrite_tar_header(STDOUT_FILENO, &header);
|
||||
}
|
||||
|
||||
static void archivefile(const char *path)
|
||||
|
Reference in New Issue
Block a user