Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: arctanb/srtm
static inline uint16_t read_lat_long(int32_t east, int32_t north) {
  char fname[20];
  uint32_t rel_east, rel_north;
  get_file_params(east, north, fname, &rel_east, &rel_north);
  FILE *file = fopen(fname, "r");
  if (!file) {
    fprintf(stderr, "could not open file %s\n", fname);
  }
  uint16_t ret = read_rel_lat_long(file, rel_east, rel_north);
  fclose(file);
  return ret;
}