aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'rpmoffset.c')
-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;
}