aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyberjun <cyberjun@gmail.com>2008-05-31 17:03:02 -0400
committerMike Frysinger <vapier@gentoo.org>2008-05-31 17:11:49 -0400
commitd44406c4deb1789994c3b2c60ee0007dbfd6a438 (patch)
treee123630208492eff8e8bd7c3797941c88ec440e2
parentrewrite and cleanup (diff)
downloadrpm2targz-9.0.0.0g.tar.gz
rpm2targz-9.0.0.0g.tar.bz2
rpm2targz-9.0.0.0g.zip
rpmoffset: cleanup and remove size limit on cpio offsetv9.0.0.0g
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--rpmoffset.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/rpmoffset.c b/rpmoffset.c
index 524e310..32ccba2 100644
--- a/rpmoffset.c
+++ b/rpmoffset.c
@@ -4,29 +4,38 @@
/* Wouldn't it be a lot more sane if we could just untar these things? */
+#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
-/* These offsets keep getting bigger, so we're going to just bite a 2MB */
-/* chunk of RAM right away so that we have enough. Yeah, horrible */
-/* quick and dirty implementation, but hey -- it gets the job done. */
+int main(int argc, char *argv[])
+{
+ size_t i;
+ char p[3];
-#define RPMBUFSIZ 2097152
+ if (argc != 1) {
+ puts("Usage: rpmoffset < rpmfile");
+ return 1;
+ }
-main()
-{
- char *buff = malloc(RPMBUFSIZ),*eb,*p;
- for (p = buff, eb = buff + read(0,buff,RPMBUFSIZ); p < eb; p++)
- {
- if (*p == '\037' && p[1] == '\213' && p[2] == '\010')
- {
- printf("%d\n",p - buff);
- exit(0);
- }
- else if (*p == 'B' && p[1] == 'Z' && p[2] == 'h')
- {
- printf("%d\n",p - buff);
- exit(0);
- }
- }
- exit(1);
+ if (read(0,p,3) != 3)
+ return 2;
+
+ for (i = 0; p[2] != 0 || p[2] != -1; ++i) {
+ if (p[0] == '\037' && p[1] == '\213' && p[2] == '\010') {
+ printf("%zu\n", i);
+ return 0;
+
+ } else if (p[0] == 'B' && p[1] == 'Z' && p[2] == 'h') {
+ printf("%zu\n", i);
+ return 0;
+ }
+
+ p[0] = p[1];
+ p[1] = p[2];
+ if (read(0, p+2, 1) != 1)
+ return 2;
+ }
+
+ return 1;
}