aboutsummaryrefslogtreecommitdiff
path: root/archival
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
parent943e81f5db56eedbadf43459afbc967d100f9da2 (diff)
downloadbusybox-e6a87e74837ba5f2f2207a75cd825acf8cf28afb.tar.gz
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 'archival')
-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
}
/* Put an octal string into the specified buffer.
- * The number is zero padded and possibly null terminated.
+ * The number is zero padded and possibly NUL terminated.
* Stores low-order bits only if whole value does not fit. */
static void putOctal(char *cp, int len, off_t value)
{
@@ -283,31 +283,32 @@ static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static void writeLongname(int fd, int type, const char *name, int dir)
{
- static const struct {
+ struct prefilled {
char mode[8]; /* 100-107 */
char uid[8]; /* 108-115 */
char gid[8]; /* 116-123 */
char size[12]; /* 124-135 */
char mtime[12]; /* 136-147 */
- } prefilled = {
- "0000000",
- "0000000",
- "0000000",
- "00000000000",
- "00000000000",
};
struct tar_header_t header;
int size;
+ memset(&header, 0, sizeof(header));
+ header.typeflag = type;
+ strcpy(header.name, "././@LongLink");
+ /* This sets mode/uid/gid/mtime to "00...00<NUL>" strings */
+ memset(header.mode, '0', sizeof(struct prefilled));
+ header.mode [sizeof(header.mode ) - 1] = '\0';
+ header.uid [sizeof(header.uid ) - 1] = '\0';
+ header.gid [sizeof(header.gid ) - 1] = '\0';
+ /* header.size is filled by '0' now, will be corrected below */
+ header.mtime[sizeof(header.mtime) - 1] = '\0';
+
dir = !!dir; /* normalize: 0/1 */
size = strlen(name) + 1 + dir; /* GNU tar uses strlen+1 */
/* + dir: account for possible '/' */
- memset(&header, 0, sizeof(header));
- strcpy(header.name, "././@LongLink");
- memcpy(header.mode, prefilled.mode, sizeof(prefilled));
PUT_OCTAL(header.size, size);
- header.typeflag = type;
chksum_and_xwrite(fd, &header);
/* Write filename[/] and pad the block. */