mirror of https://github.com/mirror/busybox.git
tar: small fix and small optimization
parent
43bddf31e9
commit
87cd4a87e3
|
@ -152,9 +152,11 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||||
if (!longname && parse_names) {
|
if (!longname && parse_names) {
|
||||||
/* we trash mode[0] here, it's ok */
|
/* we trash mode[0] here, it's ok */
|
||||||
tar.name[sizeof(tar.name)] = '\0';
|
tar.name[sizeof(tar.name)] = '\0';
|
||||||
if (tar.prefix[0])
|
if (tar.prefix[0]) {
|
||||||
|
/* and padding[0] */
|
||||||
|
tar.prefix[sizeof(tar.prefix)] = '\0';
|
||||||
file_header->name = concat_path_file(tar.prefix, tar.name);
|
file_header->name = concat_path_file(tar.prefix, tar.name);
|
||||||
else
|
} else
|
||||||
file_header->name = xstrdup(tar.name);
|
file_header->name = xstrdup(tar.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,9 +150,8 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo * hlInfo, struct stat *statbu
|
||||||
|
|
||||||
/* Put an octal string into the specified buffer.
|
/* Put an octal string into the specified buffer.
|
||||||
* The number is zero padded and possibly null terminated.
|
* The number is zero padded and possibly null terminated.
|
||||||
* Stores low-order bits only if whole value does not fit.
|
* Stores low-order bits only if whole value does not fit. */
|
||||||
* Returns FALSE if that happens. */
|
static void putOctal(char *cp, int len, off_t value)
|
||||||
static int putOctal(char *cp, int len, off_t value)
|
|
||||||
{
|
{
|
||||||
char tempBuffer[sizeof(off_t)*3+1];
|
char tempBuffer[sizeof(off_t)*3+1];
|
||||||
char *tempString = tempBuffer;
|
char *tempString = tempBuffer;
|
||||||
|
@ -169,10 +168,6 @@ static int putOctal(char *cp, int len, off_t value)
|
||||||
|
|
||||||
/* Copy the string to the field */
|
/* Copy the string to the field */
|
||||||
memcpy(cp, tempString, len);
|
memcpy(cp, tempString, len);
|
||||||
|
|
||||||
/* If after shift we have zero - value did not overflow, */
|
|
||||||
/* return 1 (TRUE) then */
|
|
||||||
return (value >> (len*3)) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write out a tar header for the specified file/directory/whatever */
|
/* Write out a tar header for the specified file/directory/whatever */
|
||||||
|
@ -239,14 +234,15 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||||
} else if (S_ISFIFO(statbuf->st_mode)) {
|
} else if (S_ISFIFO(statbuf->st_mode)) {
|
||||||
header.typeflag = FIFOTYPE;
|
header.typeflag = FIFOTYPE;
|
||||||
} else if (S_ISREG(statbuf->st_mode)) {
|
} else if (S_ISREG(statbuf->st_mode)) {
|
||||||
header.typeflag = REGTYPE;
|
if (sizeof(statbuf->st_size) > 4
|
||||||
if ((PUT_OCTAL(header.size, statbuf->st_size) == FALSE)
|
&& statbuf->st_size > (off_t)0777777777777LL
|
||||||
&& sizeof(statbuf->st_size) > 4
|
|
||||||
) {
|
) {
|
||||||
bb_error_msg_and_die("cannot store file '%s' "
|
bb_error_msg_and_die("cannot store file '%s' "
|
||||||
"of size %"OFF_FMT"d, aborting",
|
"of size %"OFF_FMT"d, aborting",
|
||||||
fileName, statbuf->st_size);
|
fileName, statbuf->st_size);
|
||||||
}
|
}
|
||||||
|
header.typeflag = REGTYPE;
|
||||||
|
PUT_OCTAL(header.size, statbuf->st_size);
|
||||||
} else {
|
} else {
|
||||||
bb_error_msg("%s: unknown file type", fileName);
|
bb_error_msg("%s: unknown file type", fileName);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Reference in New Issue