summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-01-24 23:05:25 +0100
committerMichael Vogt <mvo@debian.org>2014-01-24 23:05:25 +0100
commit48e48cbdc47a0b29ac1b9d2b7d4eef61be73d06d (patch)
tree6c464b7197ba374f9952aeb1571e15a1453183f2 /methods
parentb18dd45f2c71fbdf5c0eef113e9e8e01f84b70a7 (diff)
parent34f7c486b10559997849c15c6b51577ec3f96bc1 (diff)
Merge remote-tracking branch 'mvo/debian/sid' into debian/experimental-no-abi-break
Diffstat (limited to 'methods')
-rw-r--r--methods/rred.cc39
1 files changed, 20 insertions, 19 deletions
diff --git a/methods/rred.cc b/methods/rred.cc
index 313166160..d17ab110d 100644
--- a/methods/rred.cc
+++ b/methods/rred.cc
@@ -351,14 +351,27 @@ class Patch {
FileChanges filechanges;
MemBlock add_text;
+ static bool retry_fwrite(char *b, size_t l, FILE *f, Hashes *hash)
+ {
+ size_t r = 1;
+ while (r > 0 && l > 0)
+ {
+ r = fwrite(b, 1, l, f);
+ if (hash)
+ hash->Add((unsigned char*)b, r);
+ l -= r;
+ b += r;
+ }
+ return l == 0;
+ }
+
static void dump_rest(FILE *o, FILE *i, Hashes *hash)
{
char buffer[BLOCK_SIZE];
size_t l;
while (0 < (l = fread(buffer, 1, sizeof(buffer), i))) {
- fwrite(buffer, 1, l, o);
- if (hash)
- hash->Add((unsigned char*)buffer, l);
+ if (!retry_fwrite(buffer, l, o, hash))
+ break;
}
}
@@ -372,10 +385,7 @@ class Patch {
l = strlen(buffer);
if (l == 0 || buffer[l-1] == '\n')
n--;
- fwrite(buffer, 1, l, o);
-
- if (hash)
- hash->Add((unsigned char*)buffer, l);
+ retry_fwrite(buffer, l, o, hash);
}
}
@@ -392,17 +402,8 @@ class Patch {
}
}
- static bool dump_mem(FILE *o, char *p, size_t s, Hashes *hash) {
- size_t r;
- while (s > 0) {
- r = fwrite(p, 1, s, o);
- if (hash)
- hash->Add((unsigned char*)p, s);
- s -= r;
- p += r;
- if (r == 0) return false;
- }
- return true;
+ static void dump_mem(FILE *o, char *p, size_t s, Hashes *hash) {
+ retry_fwrite(p, s, o, hash);
}
public:
@@ -455,7 +456,7 @@ class Patch {
filechanges.add_change(ch);
break;
}
- } else { /* !cmdwaanted */
+ } else { /* !cmdwanted */
if (buffer[0] == '.' && buffer[1] == '\n') {
cmdwanted = true;
filechanges.add_change(ch);