]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
cmd/random: support lengths that aren't a multiple of 1k.
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 25 Jun 2010 17:12:29 +0000 (13:12 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 25 Jun 2010 17:12:45 +0000 (13:12 -0400)
Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/_hashsplit.c

index 937b3ad578e20a654b2d21cfde970222cc5ceedf..ce2be0fa4a5bf34405f0c94d843c8c2cc09f4e0b 100644 (file)
@@ -124,6 +124,18 @@ static PyObject *write_random(PyObject *self, PyObject *args)
            fprintf(stderr, "Random: %lld Mbytes\r", kbytes/1024);
     }
     
+    // handle non-multiples of 1024
+    if (len % 1024)
+    {
+       int i;
+       for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
+           buf[i] = random();
+       ret = write(fd, buf, len % 1024);
+       if (ret < 0)
+           ret = 0;
+       written += ret;
+    }
+    
     if (kbytes/1024 > 0)
        fprintf(stderr, "Random: %lld Mbytes, done.\n", kbytes/1024);
     return Py_BuildValue("L", written);