Esempio n. 1
0
/*
 * raises: EOF_ERROR
 */
static void cmpdi_read_i(InStream *is, uchar *b, int len)
{
    CompoundInStream *cis = is->d.cis;
    off_t start = is_pos(is);

    if ((start + len) > cis->length) {
        RAISE(EOF_ERROR, "Tried to read past end of file. File length is "
              "<%"F_OFF_T_PFX"d> and tried to read to <%"F_OFF_T_PFX"d>",
              cis->length, start + len);
    }

    is_seek(cis->sub, cis->offset + start);
    is_read_bytes(cis->sub, b, len);
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
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);
}