lkml.org 
[lkml]   [2000]   [Oct]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: want tool to open RPM package on Window 95
Michal Jaegermann writes:
> > Somewhere floating around there is a perl version of rpm2cpio.
>
> This is what I wrote one day a long time ago:
>
> #!/usr/bin/perl -w
> use strict;
>
> my ($buffer, $pos, $gzmagic);
> $gzmagic = "\037\213";
> open OUT, "| gunzip" or die "cannot find gunzip; $!\n";
> while(1) {
> exit 1 unless defined($pos = read STDIN, $buffer, 8192) and $pos > 0;
> next unless ($pos = index $buffer, $gzmagic) >= 0;
> print OUT substr $buffer, $pos;
> last;
> }
> print OUT <STDIN>;
> exit 0;
>
> Yes, I know that I should not mix 'read' with stdio but it worked
> every time I tried the above. :-)

The good news is that "read" does use stdio (along with seek and print).
The syscall ones are sys{read,write,seek}. The less good news is that
your "print OUT <STDIN>" sucks up all the RPM file into memory before
dumping it out again which is inelegant and leads those who copy the
idiom without understanding it to run into problems when they use
similar code on large files. One way of doing it a bit differently is

#!/usr/bin/perl
die "Usage: rpm2cpio foo.rpm | cpio ...\n" unless @ARGV == 1;
open(RPM, $ARGV[0]) or die "$ARGV[0]: $!\n";
open(STDOUT, "| gunzip") or die "cannot find gunzip: $!\n";
while (read(RPM, $_, 8192)) {
if (!$found_gzmagic) {
s/^.*?(?=\037\213)//s or next;
$found_gzmagic = 1;
}
print;
}

> Can we go back now to kernel issues?

Oops, yes, we now return you to your regularly scheduled kgcc wars.

--Malcolm

--
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Unix Systems Programmer
Oxford University Computing Services
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:41    [W:0.027 / U:3.972 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site