aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-05-30 05:10:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-05-30 05:10:16 +0200
commitc88c1a01904b5791dfd1ca5342c805a9f392e17f (patch)
tree5e7dad7e81657d02b99a0fe31442364344e965fe
parentacaaca839abada0d0718375ba03dcaeddda15d9e (diff)
downloadbusybox-c88c1a01904b5791dfd1ca5342c805a9f392e17f.tar.gz
rpm2cpio: teach it to understand xz format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/rpm2cpio.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 4ed5b023b..598ec8670 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -68,22 +68,35 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
#else
/* BLOAT */
{
- unsigned char magic[2];
+ unsigned char magic[8];
IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
xread(rpm_fd, &magic, 2);
- unpack = unpack_gz_stream;
- if (magic[0] != 0x1f || magic[1] != 0x8b) {
- if (!ENABLE_FEATURE_SEAMLESS_BZ2
- || magic[0] != 'B' || magic[1] != 'Z'
- ) {
- bb_error_msg_and_die("invalid gzip"
- IF_FEATURE_SEAMLESS_BZ2("/bzip2")
- " magic");
- }
+ if (magic[0] == 0x1f && magic[1] == 0x8b) {
+ unpack = unpack_gz_stream;
+ } else
+ if (ENABLE_FEATURE_SEAMLESS_BZ2
+ && magic[0] == 'B' && magic[1] == 'Z'
+ ) {
unpack = unpack_bz2_stream;
+ } else
+ if (ENABLE_FEATURE_SEAMLESS_XZ
+ && magic[0] == 0xfd && magic[1] == '7'
+ ) {
+ /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */
+ /* More info at: http://tukaani.org/xz/xz-file-format.txt */
+ xread(rpm_fd, magic + 2, 4);
+ if (strcmp((char*)magic + 2, "zXZ") != 0)
+ goto no_magic;
+ xlseek(rpm_fd, -6, SEEK_CUR);
+ unpack = unpack_xz_stream;
+ } else {
+ no_magic:
+ bb_error_msg_and_die("no gzip"
+ IF_FEATURE_SEAMLESS_BZ2("/bzip2")
+ IF_FEATURE_SEAMLESS_XZ("/xz")
+ " magic");
}
-
if (unpack(rpm_fd, STDOUT_FILENO) < 0)
bb_error_msg_and_die("error unpacking");
}