/* */ #include "PreAllocationDiskWriter.h" #include "DlAbortEx.h" #include "message.h" #include #include #include #include #include #include PreAllocationDiskWriter::PreAllocationDiskWriter(long long int totalLength) :AbstractDiskWriter(),totalLength(totalLength) {} PreAllocationDiskWriter::~PreAllocationDiskWriter() {} void PreAllocationDiskWriter::initAndOpenFile(const string& filename) { createFile(filename); int bufSize = 4096; char buf[4096]; memset(buf, 0, bufSize); long long int x = totalLength/bufSize; int r = totalLength%bufSize; for(long long int i = 0; i < x; i++) { if(write(fd, buf, bufSize) < 0) { throw new DlAbortEx(EX_FILE_WRITE, filename.c_str(), strerror(errno)); } } if(r > 0) { seek(totalLength-r); if(write(fd, buf, r) < 0) { throw new DlAbortEx(EX_FILE_WRITE, filename.c_str(), strerror(errno)); } } }