Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use readall, compatibility on 32bit systems

  • Loading branch information...
commit c03f98f2cfef14da5b061d6e7a12b9ecd6a7e50b 1 parent 2b7cf19
Kazuho Oku authored
Showing with 24 additions and 5 deletions.
  1. +23 −4 blockdiff_dump
  2. +1 −1  blockdiff_merge
View
27 blockdiff_dump
@@ -5,6 +5,7 @@ use strict;
use warnings;
use Digest::MD5 qw(md5);
+use Errno;
# file descriptors:
# 0 < data file
@@ -12,6 +13,24 @@ use Digest::MD5 qw(md5);
# 5 < old digest (optional)
# 6 > new digest
+sub readall {
+ my ($fh, $buf, $len) = @_;
+ my $off = 0;
+ while ($off != $len) {
+ my $r = sysread($fh, $$buf, $len - $off, $off);
+ if ($r == 0) {
+ return $off;
+ } elsif ($r == -1) {
+ if ($! != Errno::EAGAIN) {
+ return $off || -1;
+ }
+ } else {
+ $off += $r;
+ }
+ }
+ return $off;
+}
+
my $blocksize = $ENV{BLOCKSIZE} || 16384;
# open files
@@ -19,7 +38,7 @@ open my $new_digest_fp, '>&=', 6
or die "cloud not open digest data output (fd:6):$!";
my $orig_digest_fp;
if (open $orig_digest_fp, '<&=', 5) {
- sysread($orig_digest_fp, my $bsbin, 4) == 4
+ readall($orig_digest_fp, \my $bsbin, 4) == 4
or die "old digest data is corrupt";
$blocksize = unpack 'V', $bsbin;
} else {
@@ -33,20 +52,20 @@ syswrite($new_digest_fp, pack('V', $blocksize)) == 4
or die "failed to write digest data (fd:6):$!";
for (my $offset = 0;
- (my $rlen = sysread(STDIN, my $block, $blocksize)) != 0;
+ (my $rlen = readall(\*STDIN, \my $block, $blocksize)) != 0;
$offset += $rlen) {
die "failed to read data:$!"
if $rlen == -1;
my $digest = md5($block);
my $orig_digest;
if ($orig_digest_fp
- && (sysread($orig_digest_fp, $orig_digest, length $digest)
+ && (readall($orig_digest_fp, \$orig_digest, length $digest)
== length $digest)
&& $digest eq $orig_digest) {
# no need to dump data
} else {
# dump data
- (syswrite(STDOUT, pack('V2', $offset & 0xffffffff, $offset >> 32)) == 8
+ (syswrite(STDOUT, pack('V2', $offset % 2**32, $offset / 2**32)) == 8
and syswrite(STDOUT, $block) == $rlen)
or die "failed to write patch data (fd:1):$!";
}
View
2  blockdiff_merge
@@ -44,7 +44,7 @@ while (readall(\*STDIN, \my $offbin, 8) == 8) {
if $rlen <= 0;
my $offset = do {
my @o = unpack 'V2', $offbin;
- $o[0] + $o[1] * (1<<32);
+ $o[0] + $o[1] * 2**32;
};
warn "writing at:$offset, size:$rlen" if $DEBUG;
sysseek $fh, $offset, 0
Please sign in to comment.
Something went wrong with that request. Please try again.