aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-08-01 15:07:21 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-08-01 15:07:21 +0200
commite6a87e74837ba5f2f2207a75cd825acf8cf28afb (patch)
treef8a4f760708df5629c8ca651d139d8ab15ab19eb /archival/tar.c
parent943e81f5db56eedbadf43459afbc967d100f9da2 (diff)
downloadbusybox-w32-e6a87e74837ba5f2f2207a75cd825acf8cf28afb.tar.gz
busybox-w32-e6a87e74837ba5f2f2207a75cd825acf8cf28afb.tar.bz2
busybox-w32-e6a87e74837ba5f2f2207a75cd825acf8cf28afb.zip
tar: code shrink
function old new delta writeLongname 226 228 +2 static.prefilled 48 - -48 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 2/-48) Total: -46 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--archival/tar.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/archival/tar.c b/archival/tar.c
index ca802f73c..f10781a58 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -232,7 +232,7 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf
232} 232}
233 233
234/* Put an octal string into the specified buffer. 234/* Put an octal string into the specified buffer.
235 * The number is zero padded and possibly null terminated. 235 * The number is zero padded and possibly NUL terminated.
236 * Stores low-order bits only if whole value does not fit. */ 236 * Stores low-order bits only if whole value does not fit. */
237static void putOctal(char *cp, int len, off_t value) 237static void putOctal(char *cp, int len, off_t value)
238{ 238{
@@ -283,31 +283,32 @@ static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
283# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 283# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
284static void writeLongname(int fd, int type, const char *name, int dir) 284static void writeLongname(int fd, int type, const char *name, int dir)
285{ 285{
286 static const struct { 286 struct prefilled {
287 char mode[8]; /* 100-107 */ 287 char mode[8]; /* 100-107 */
288 char uid[8]; /* 108-115 */ 288 char uid[8]; /* 108-115 */
289 char gid[8]; /* 116-123 */ 289 char gid[8]; /* 116-123 */
290 char size[12]; /* 124-135 */ 290 char size[12]; /* 124-135 */
291 char mtime[12]; /* 136-147 */ 291 char mtime[12]; /* 136-147 */
292 } prefilled = {
293 "0000000",
294 "0000000",
295 "0000000",
296 "00000000000",
297 "00000000000",
298 }; 292 };
299 struct tar_header_t header; 293 struct tar_header_t header;
300 int size; 294 int size;
301 295
296 memset(&header, 0, sizeof(header));
297 header.typeflag = type;
298 strcpy(header.name, "././@LongLink");
299 /* This sets mode/uid/gid/mtime to "00...00<NUL>" strings */
300 memset(header.mode, '0', sizeof(struct prefilled));
301 header.mode [sizeof(header.mode ) - 1] = '\0';
302 header.uid [sizeof(header.uid ) - 1] = '\0';
303 header.gid [sizeof(header.gid ) - 1] = '\0';
304 /* header.size is filled by '0' now, will be corrected below */
305 header.mtime[sizeof(header.mtime) - 1] = '\0';
306
302 dir = !!dir; /* normalize: 0/1 */ 307 dir = !!dir; /* normalize: 0/1 */
303 size = strlen(name) + 1 + dir; /* GNU tar uses strlen+1 */ 308 size = strlen(name) + 1 + dir; /* GNU tar uses strlen+1 */
304 /* + dir: account for possible '/' */ 309 /* + dir: account for possible '/' */
305 310
306 memset(&header, 0, sizeof(header));
307 strcpy(header.name, "././@LongLink");
308 memcpy(header.mode, prefilled.mode, sizeof(prefilled));
309 PUT_OCTAL(header.size, size); 311 PUT_OCTAL(header.size, size);
310 header.typeflag = type;
311 chksum_and_xwrite(fd, &header); 312 chksum_and_xwrite(fd, &header);
312 313
313 /* Write filename[/] and pad the block. */ 314 /* Write filename[/] and pad the block. */