static void copy_files(const char *fname, void *arg) { struct CopyFileArg *cfa = (struct CopyFileArg *)arg; OutStream *os = cfa->to_store->new_output(cfa->to_store, fname); InStream *is = cfa->from_store->open_input(cfa->from_store, fname); int len = (int)is_length(is); uchar *buffer = ALLOC_N(uchar, len + 1); is_read_bytes(is, buffer, len); os_write_bytes(os, buffer, len); is_close(is); os_close(os); free(buffer); }
void ramo_write_to(OutStream *os, OutStream *other_o) { int i, len; RAMFile *rf = os->file.rf; int last_buffer_number; int last_buffer_offset; os_flush(os); last_buffer_number = (int) (rf->len / BUFFER_SIZE); last_buffer_offset = rf->len % BUFFER_SIZE; for (i = 0; i <= last_buffer_number; i++) { len = (i == last_buffer_number ? last_buffer_offset : BUFFER_SIZE); os_write_bytes(other_o, rf->buffers[i], len); } }
static void cw_copy_file(CompoundWriter *cw, CWFileEntry *src, OutStream *os) { off_t start_ptr = os_pos(os); off_t end_ptr; off_t remainder, length, len; uchar buffer[BUFFER_SIZE]; InStream *is = cw->store->open_input(cw->store, src->name); remainder = length = is_length(is); while (remainder > 0) { len = MIN(remainder, BUFFER_SIZE); is_read_bytes(is, buffer, len); os_write_bytes(os, buffer, len); remainder -= len; } /* Verify that remainder is 0 */ if (remainder != 0) { RAISE(IO_ERROR, "There seems to be an error in the compound file " "should have read to the end but there are <%"F_OFF_T_PFX"d> " "bytes left", remainder); } /* Verify that the output length diff is equal to original file */ end_ptr = os_pos(os); len = end_ptr - start_ptr; if (len != length) { RAISE(IO_ERROR, "Difference in compound file output file offsets " "<%"F_OFF_T_PFX"d> does not match the original file lenght " "<%"F_OFF_T_PFX"d>", len, length); } is_close(is); }