gunzip: restore mtime. approx +80 bytes of code

rpm: make code more robust
lsmod: small code shrink
This commit is contained in:
Denis Vlasenko
2008-11-01 12:54:56 +00:00
parent 5a89763fb7
commit 1a9e9bdd93
8 changed files with 69 additions and 28 deletions

View File

@@ -1108,18 +1108,21 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
return res;
}
static int check_header_gzip(STATE_PARAM_ONLY)
static int check_header_gzip(STATE_PARAM unpack_info_t *info)
{
union {
unsigned char raw[8];
struct {
uint8_t gz_method;
uint8_t flags;
//uint32_t mtime; - unused fields
//uint8_t xtra_flags;
//uint8_t os_flags;
} formatted; /* packed */
uint32_t mtime;
uint8_t xtra_flags_UNUSED;
uint8_t os_flags_UNUSED;
} __attribute__((packed)) formatted;
} header;
struct BUG_header {
char BUG_header[sizeof(header) == 8 ? 1 : -1];
};
/*
* Rewind bytebuffer. We use the beginning because the header has 8
@@ -1167,6 +1170,9 @@ static int check_header_gzip(STATE_PARAM_ONLY)
}
}
if (info)
info->mtime = SWAP_LE32(header.formatted.mtime);
/* Read the header checksum */
if (header.formatted.flags & 0x02) {
if (!top_up(PASS_STATE 2))
@@ -1177,7 +1183,7 @@ static int check_header_gzip(STATE_PARAM_ONLY)
}
USE_DESKTOP(long long) int FAST_FUNC
unpack_gz_stream(int in, int out)
unpack_gz_stream_with_info(int in, int out, unpack_info_t *info)
{
uint32_t v32;
USE_DESKTOP(long long) int n;
@@ -1192,7 +1198,7 @@ unpack_gz_stream(int in, int out)
gunzip_src_fd = in;
again:
if (!check_header_gzip(PASS_STATE_ONLY)) {
if (!check_header_gzip(PASS_STATE info)) {
bb_error_msg("corrupted data");
n = -1;
goto ret;
@@ -1239,3 +1245,9 @@ unpack_gz_stream(int in, int out)
DEALLOC_STATE;
return n;
}
USE_DESKTOP(long long) int FAST_FUNC
unpack_gz_stream(int in, int out)
{
return unpack_gz_stream_with_info(in, out, NULL);
}