summaryrefslogtreecommitdiff
path: root/procps/smemcap.c
diff options
context:
space:
mode:
authorDenys Vlasenko2021-08-20 17:58:49 +0200
committerDenys Vlasenko2021-08-20 17:58:49 +0200
commit62d5a1e56f4022002c5c55e02d7d29e1e68bc236 (patch)
tree2712cc1241e294c23f77528d83448853e20f3ccc /procps/smemcap.c
parent38e9c8c95b919e949b1cdd16f05b648a75983f57 (diff)
downloadbusybox-62d5a1e56f4022002c5c55e02d7d29e1e68bc236.zip
busybox-62d5a1e56f4022002c5c55e02d7d29e1e68bc236.tar.gz
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>
Diffstat (limited to 'procps/smemcap.c')
-rw-r--r--procps/smemcap.c16
1 files changed, 1 insertions, 15 deletions
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)