aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-08-20 17:58:49 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-08-20 17:58:49 +0200
commit62d5a1e56f4022002c5c55e02d7d29e1e68bc236 (patch)
tree2712cc1241e294c23f77528d83448853e20f3ccc /archival/tar.c
parent38e9c8c95b919e949b1cdd16f05b648a75983f57 (diff)
downloadbusybox-w32-62d5a1e56f4022002c5c55e02d7d29e1e68bc236.tar.gz
busybox-w32-62d5a1e56f4022002c5c55e02d7d29e1e68bc236.tar.bz2
busybox-w32-62d5a1e56f4022002c5c55e02d7d29e1e68bc236.zip
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 'archival/tar.c')
-rw-r--r--archival/tar.c31
1 files changed, 2 insertions, 29 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 94fb61a29..9de37592e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -254,32 +254,6 @@ static void putOctal(char *cp, int len, off_t value)
254} 254}
255#define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) 255#define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b))
256 256
257static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
258{
259 /* POSIX says that checksum is done on unsigned bytes
260 * (Sun and HP-UX gets it wrong... more details in
261 * GNU tar source) */
262 const unsigned char *cp;
263 int chksum, size;
264
265 strcpy(hp->magic, "ustar ");
266
267 /* Calculate and store the checksum (i.e., the sum of all of the bytes of
268 * the header). The checksum field must be filled with blanks for the
269 * calculation. The checksum field is formatted differently from the
270 * other fields: it has 6 digits, a null, then a space -- rather than
271 * digits, followed by a null like the other fields... */
272 memset(hp->chksum, ' ', sizeof(hp->chksum));
273 cp = (const unsigned char *) hp;
274 chksum = 0;
275 size = sizeof(*hp);
276 do { chksum += *cp++; } while (--size);
277 putOctal(hp->chksum, sizeof(hp->chksum)-1, chksum);
278
279 /* Now write the header out to disk */
280 xwrite(fd, hp, sizeof(*hp));
281}
282
283# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 257# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
284static void writeLongname(int fd, int type, const char *name, int dir) 258static void writeLongname(int fd, int type, const char *name, int dir)
285{ 259{
@@ -310,7 +284,7 @@ static void writeLongname(int fd, int type, const char *name, int dir)
310 /* + dir: account for possible '/' */ 284 /* + dir: account for possible '/' */
311 285
312 PUT_OCTAL(header.size, size); 286 PUT_OCTAL(header.size, size);
313 chksum_and_xwrite(fd, &header); 287 chksum_and_xwrite_tar_header(fd, &header);
314 288
315 /* Write filename[/] and pad the block. */ 289 /* Write filename[/] and pad the block. */
316 /* dir=0: writes 'name<NUL>', pads */ 290 /* dir=0: writes 'name<NUL>', pads */
@@ -441,8 +415,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
441 header_name, S_ISDIR(statbuf->st_mode)); 415 header_name, S_ISDIR(statbuf->st_mode));
442# endif 416# endif
443 417
444 /* Now write the header out to disk */ 418 chksum_and_xwrite_tar_header(tbInfo->tarFd, &header);
445 chksum_and_xwrite(tbInfo->tarFd, &header);
446 419
447 /* Now do the verbose thing (or not) */ 420 /* Now do the verbose thing (or not) */
448 if (tbInfo->verboseFlag) { 421 if (tbInfo->verboseFlag) {