From 62d5a1e56f4022002c5c55e02d7d29e1e68bc236 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 20 Aug 2021 17:58:49 +0200 Subject: 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 --- procps/smemcap.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'procps/smemcap.c') diff --git a/procps/smemcap.c b/procps/smemcap.c index 2f8ab19..2f1897d 100644 --- a/procps/smemcap.c +++ b/procps/smemcap.c @@ -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) -- cgit v1.1