diff options
Diffstat (limited to 'rpm2cpio.c')
-rw-r--r-- | rpm2cpio.c | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/rpm2cpio.c b/rpm2cpio.c deleted file mode 100644 index 8d639d6ad..000000000 --- a/rpm2cpio.c +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini rpm2cpio implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2001 by Laurence Anderson | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include "busybox.h" | ||
23 | #include <netinet/in.h> /* For ntohl & htonl function */ | ||
24 | #include <string.h> | ||
25 | |||
26 | #define RPM_MAGIC "\355\253\356\333" | ||
27 | #define RPM_HEADER_MAGIC "\216\255\350" | ||
28 | |||
29 | struct rpm_lead { | ||
30 | unsigned char magic[4]; | ||
31 | u_int8_t major, minor; | ||
32 | u_int16_t type; | ||
33 | u_int16_t archnum; | ||
34 | char name[66]; | ||
35 | u_int16_t osnum; | ||
36 | u_int16_t signature_type; | ||
37 | char reserved[16]; | ||
38 | }; | ||
39 | |||
40 | struct rpm_header { | ||
41 | char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */ | ||
42 | u_int8_t version; /* 1 byte version number */ | ||
43 | u_int32_t reserved; /* 4 bytes reserved */ | ||
44 | u_int32_t entries; /* Number of entries in header (4 bytes) */ | ||
45 | u_int32_t size; /* Size of store (4 bytes) */ | ||
46 | }; | ||
47 | |||
48 | void skip_header(FILE *rpmfile) | ||
49 | { | ||
50 | struct rpm_header header; | ||
51 | |||
52 | fread(&header, sizeof(struct rpm_header), 1, rpmfile); | ||
53 | if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */ | ||
54 | if (header.version != 1) error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */ | ||
55 | header.entries = ntohl(header.entries); | ||
56 | header.size = ntohl(header.size); | ||
57 | fseek (rpmfile, 16 * header.entries, SEEK_CUR); /* Seek past index entries */ | ||
58 | fseek (rpmfile, header.size, SEEK_CUR); /* Seek past store */ | ||
59 | } | ||
60 | |||
61 | /* No getopt required */ | ||
62 | extern int rpm2cpio_main(int argc, char **argv) | ||
63 | { | ||
64 | struct rpm_lead lead; | ||
65 | int gunzip_pid; | ||
66 | FILE *rpmfile, *cpiofile; | ||
67 | |||
68 | if (argc == 1) { | ||
69 | rpmfile = stdin; | ||
70 | } else { | ||
71 | rpmfile = fopen(argv[1], "r"); | ||
72 | if (!rpmfile) perror_msg_and_die("Can't open rpm file"); | ||
73 | /* set the buffer size */ | ||
74 | setvbuf(rpmfile, NULL, _IOFBF, 0x8000); | ||
75 | } | ||
76 | |||
77 | fread (&lead, sizeof(struct rpm_lead), 1, rpmfile); | ||
78 | if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */ | ||
79 | /* Skip the signature header */ | ||
80 | skip_header(rpmfile); | ||
81 | fseek(rpmfile, (8 - (ftell(rpmfile) % 8)) % 8, SEEK_CUR); /* Pad to 8 byte boundary */ | ||
82 | /* Skip the main header */ | ||
83 | skip_header(rpmfile); | ||
84 | |||
85 | cpiofile = gz_open(rpmfile, &gunzip_pid); | ||
86 | |||
87 | copyfd(fileno(cpiofile), fileno(stdout)); | ||
88 | gz_close(gunzip_pid); | ||
89 | fclose(rpmfile); | ||
90 | return 0; | ||
91 | } | ||