static imgtoolerr_t write_fork(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, UINT64 pos, UINT64 fork_len, option_resolution *opts) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; imgtool_stream *mem_stream = NULL; size_t len; if (fork_len > 0) { mem_stream = stream_open_mem(NULL, 0); if (!mem_stream) { err = IMGTOOLERR_OUTOFMEMORY; goto done; } stream_seek(sourcef, pos, SEEK_SET); len = stream_transfer(mem_stream, sourcef, fork_len); if (len < fork_len) stream_fill(mem_stream, 0, fork_len); stream_seek(mem_stream, 0, SEEK_SET); err = imgtool_partition_write_file(partition, filename, fork, mem_stream, opts, NULL); if (err) goto done; } done: if (mem_stream) stream_close(mem_stream); return err; }
static imgtoolerr_t ascii_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, option_resolution *opts) { imgtoolerr_t err; imgtool_stream *mem_stream = NULL; const char *eoln; /* create a stream */ mem_stream = stream_open_mem(NULL, 0); if (!mem_stream) { err = IMGTOOLERR_OUTOFMEMORY; goto done; } eoln = imgtool_partition_get_info_string(partition, IMGTOOLINFO_STR_EOLN); err = convert_stream_eolns(sourcef, mem_stream, eoln); if (err) goto done; stream_seek(mem_stream, SEEK_SET, 0); err = imgtool_partition_write_file(partition, filename, fork, mem_stream, opts, NULL); if (err) goto done; done: if (mem_stream) stream_close(mem_stream); return err; }
static imgtoolerr_t ascii_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; imgtool_stream *mem_stream; mem_stream = stream_open_mem(NULL, 0); if (!mem_stream) { err = IMGTOOLERR_OUTOFMEMORY; goto done; } err = imgtool_partition_read_file(partition, filename, fork, mem_stream, NULL); if (err) goto done; stream_seek(mem_stream, SEEK_SET, 0); err = convert_stream_eolns(mem_stream, destf, EOLN); if (err) goto done; done: if (mem_stream) stream_close(mem_stream); return err; }
static void node_checkfile(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; const char *filename; const char *fork; filter_getinfoproc filter; imgtool_stream *stream = NULL; UINT64 stream_sz; const void *stream_ptr; mess_pile pile; if (!state->m_partition) { state->m_failed = 1; report_message(MSG_FAILURE, "Partition not loaded"); goto done; } get_file_params(node, &filename, &fork, &filter); if (!filename) goto done; stream = stream_open_mem(NULL, 0); if (!stream) { state->m_failed = 1; error_outofmemory(); goto done; } err = imgtool_partition_read_file(state->m_partition, filename, fork, stream, filter); if (err) { state->m_failed = 1; report_imgtoolerr(err); goto done; } pile_init(&pile); messtest_get_data(node, &pile); stream_ptr = stream_getptr(stream); stream_sz = stream_size(stream); if ((pile_size(&pile) != stream_sz) || (memcmp(stream_ptr, pile_getptr(&pile), pile_size(&pile)))) { report_message(MSG_FAILURE, "Failed file verification"); goto done; } pile_delete(&pile); done: if (stream != NULL) stream_close(stream); }
static void node_putfile(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; const char *filename; const char *fork; filter_getinfoproc filter; imgtool_stream *stream = NULL; mess_pile pile; if (state->m_partition == NULL) { state->m_failed = 1; report_message(MSG_FAILURE, "Partition not loaded"); goto done; } get_file_params(node, &filename, &fork, &filter); if (filename == NULL) goto done; pile_init(&pile); messtest_get_data(node, &pile); stream = stream_open_mem(NULL, 0); if (stream == NULL) { state->m_failed = 1; error_outofmemory(); goto done; } stream_write(stream, pile_getptr(&pile), pile_size(&pile)); stream_seek(stream, 0, SEEK_SET); pile_delete(&pile); err = imgtool_partition_write_file(state->m_partition, filename, fork, stream, NULL, filter); if (err) { state->m_failed = 1; report_imgtoolerr(err); goto done; } if (VERBOSE_FILECHAIN) { char buf[1024]; err = imgtool_partition_get_chain_string(state->m_partition, filename, buf, ARRAY_LENGTH(buf)); if (err == IMGTOOLERR_SUCCESS) report_message(MSG_INFO, "Filechain '%s': %s", filename, buf); } done: if (stream != NULL) stream_close(stream); }
static int cococas_initalt(imgtool_stream *instream, imgtool_stream **outstream, int *basepos, int *length, int *channels, int *frequency, int *resolution) { int caslength; int numsamples; int samplepos; UINT8 *bytes = NULL; INT16 *buffer = NULL; INT16 *newbuffer; caslength = stream_size(instream); bytes = malloc(caslength); if (!bytes) goto outofmemory; stream_read(instream, bytes, caslength); numsamples = COCO_WAVESAMPLES_HEADER + COCO_WAVESAMPLES_TRAILER + (caslength * 8*8); buffer = malloc(numsamples * sizeof(INT16)); if (!buffer) goto outofmemory; coco_wave_size = caslength; samplepos = 0; samplepos += coco_cassette_fill_wave(&buffer[samplepos], COCO_WAVESAMPLES_HEADER, CODE_HEADER); samplepos += coco_cassette_fill_wave(&buffer[samplepos], caslength, bytes); samplepos += coco_cassette_fill_wave(&buffer[samplepos], COCO_WAVESAMPLES_TRAILER, CODE_TRAILER); free(bytes); bytes = NULL; newbuffer = realloc(buffer, samplepos * sizeof(INT16)); if (!newbuffer) goto outofmemory; buffer = newbuffer; *outstream = stream_open_mem(buffer, samplepos * sizeof(INT16)); if (!(*outstream)) goto outofmemory; *basepos = 0; *length = samplepos * 2; *channels = 1; *frequency = 4800; *resolution = 16; return 0; outofmemory: if (bytes) free(bytes); if (buffer) free(buffer); return IMGTOOLERR_OUTOFMEMORY; }
static NATIVECALL(mem_stream){ Link link = object_create(stream_type); link->value.vptr = stream_open_mem(); return link; }