#include <boost/foreach.hpp>
#include <iostream>
+using std::bad_alloc;
using std::cin;
using std::min;
using std::string;
throw CopyError (String::compose("Failed to open file %1", from.string()), 0);
}
- uint8_t* buffer = new uint8_t[block_size];
+ uint8_t* buffer = aligned_alloc (4096, block_size);
+ if (!buffer) {
+ throw bad_alloc();
+ }
Digester digester;
int progress_frequency = 5000;
if (read != this_time) {
fclose (in);
ext4_fclose (&out);
- delete[] buffer;
+ free (buffer);
throw CopyError (String::compose("Short read; expected %1 but read %2", this_time, read), 0);
}
if (r != EOK) {
fclose (in);
ext4_fclose (&out);
- delete[] buffer;
+ free (buffer);
throw CopyError ("Write failed", r);
}
if (written != this_time) {
fclose (in);
ext4_fclose (&out);
- delete[] buffer;
+ free (buffer);
throw CopyError (String::compose("Short write; expected %1 but wrote %2", this_time, written), 0);
}
remaining -= this_time;
fclose (in);
ext4_fclose (&out);
- delete[] buffer;
+ free (buffer);
return digester.get ();
}