--- rpm2cpio.orig 2010-04-17 10:42:49.000000000 -0400 +++ rpm2cpio 2010-04-17 10:43:43.000000000 -0400 @@ -33,6 +33,7 @@ # add a path if desired $gzip = "gzip"; $bzip2 = "bzip2"; +$lzma = "lzma"; sub printhelp { print <= 0 && pos & 7) { + pos += 7; + pos &= ~7; + fseek(infile, pos, SEEK_SET); + myread(16); + } + if (strncmp(buffer, HEADER_MAGIC, 4)) { + fprintf(stderr, "unrecognized RPM header\n"); + exit(1); + } + sections = unpack(buffer + 8); + bytes = unpack(buffer + 12); + if (pos >= 0) { + pos += 16; + pos += 16 * sections; + pos += bytes; + fseek(infile, pos, SEEK_SET); + } else - status = 0; + { + for (pos = (16 * sections) + bytes; pos >= BUFSIZE; pos -= BUFSIZE) + myread(BUFSIZE); + if (pos) + myread(pos); + } + } + + if (status_gz) { + strcat(outname, ".cpio.gz"); + } + else if (status_lzma) { + strcat(outname, ".cpio.lzma"); + } + else { + fprintf(stderr, "no cpio file in RPM file\n"); + exit(1); } - buffer[0] = GZ_MAGIC_1; - buffer[1] = GZ_MAGIC_2; - if (write(outfile, buffer, 2) < 0) { + + /* Open output file */ + if (infile == stdin) + outfile = STDOUT_FILENO; + else if ((outfile = open(outname, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { + perror(progname); + exit(1); + } + + if (write(outfile, buffer, 16) < 0) { perror(progname); exit(1); } /* Now simply copy the GZIP archive into the output file */ - while ((len = read(infile, buffer, BUFSIZE)) > 0) { + while ((len = fread(buffer, 1, BUFSIZE, infile)) > 0) { if (write(outfile, buffer, len) < 0) { perror(progname); exit(1); @@ -140,6 +202,6 @@ exit(1); } close(outfile); - close(infile); + fclose(infile); exit(0); }