in hfs/hfslib.c [80:134]
void writeToHFSFile(HFSPlusCatalogFile* file, AbstractFile* input, Volume* volume) {
unsigned char *buffer;
io_func* io;
off_t curPosition;
off_t bytesLeft;
buffer = (unsigned char*) malloc(BUFSIZE);
bytesLeft = input->getLength(input);
if(file->permissions.ownerFlags & UF_COMPRESSED) {
io = openHFSPlusCompressed(volume, file);
if(io == NULL) {
hfs_panic("error opening file");
free(buffer);
return;
}
} else {
io = openRawFile(file->fileID, &file->dataFork, (HFSPlusCatalogRecord*)file, volume);
if(io == NULL) {
hfs_panic("error opening file");
free(buffer);
return;
}
allocate((RawFile*)io->data, bytesLeft);
}
curPosition = 0;
while(bytesLeft > 0) {
if(bytesLeft > BUFSIZE) {
if(input->read(input, buffer, BUFSIZE) != BUFSIZE) {
hfs_panic("error reading");
}
if(!WRITE(io, curPosition, BUFSIZE, buffer)) {
hfs_panic("error writing");
}
curPosition += BUFSIZE;
bytesLeft -= BUFSIZE;
} else {
if(input->read(input, buffer, (size_t)bytesLeft) != (size_t)bytesLeft) {
hfs_panic("error reading");
}
if(!WRITE(io, curPosition, (size_t)bytesLeft, buffer)) {
hfs_panic("error reading");
}
curPosition += bytesLeft;
bytesLeft -= bytesLeft;
}
}
CLOSE(io);
free(buffer);
}