about summary refs log tree commit diff
path: root/src/engine/e_datafile.c
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-12 12:27:55 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-12 12:27:55 +0000
commit47a0525ab8f99180e1d7a1a74fb6ca620c08f7b5 (patch)
treebe5be984123acb9df49739c4daa50fc9ea92ff80 /src/engine/e_datafile.c
parent1c1677f02300e5ab10bca9c74ce7f49d4605b9d6 (diff)
downloadzcatch-47a0525ab8f99180e1d7a1a74fb6ca620c08f7b5.tar.gz
zcatch-47a0525ab8f99180e1d7a1a74fb6ca620c08f7b5.zip
merged editor over to trunk
Diffstat (limited to 'src/engine/e_datafile.c')
-rw-r--r--src/engine/e_datafile.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/engine/e_datafile.c b/src/engine/e_datafile.c
index 14138ed9..f0c70f58 100644
--- a/src/engine/e_datafile.c
+++ b/src/engine/e_datafile.c
@@ -251,6 +251,23 @@ void *datafile_get_data(DATAFILE *df, int index)
 	return df->data_ptrs[index];
 }
 
+void *datafile_get_data_swapped(DATAFILE *df, int index)
+{
+	void *ptr = datafile_get_data(df, index);
+	int size = datafile_get_datasize(df, index);
+	(void)size; /* not used on LE machines */
+	
+	if(!ptr)
+		return ptr;
+
+#if defined(CONF_ARCH_ENDIAN_BIG)
+	swap_endian(ptr, sizeof(int), size);
+#endif
+
+	return ptr;
+}
+
+
 void datafile_unload_data(DATAFILE *df, int index)
 {
 	/* */
@@ -429,8 +446,8 @@ int datafile_add_item(DATAFILE_OUT *df, int type, int id, int size, void *data)
 int datafile_add_data(DATAFILE_OUT *df, int size, void *data)
 {
 	DATA_INFO *info = &df->datas[df->num_datas];
-	void *compdata = mem_alloc(size, 1); /* temporary buffer that we use duing compression */
-	unsigned long s = size;
+	unsigned long s = size*2;
+	void *compdata = mem_alloc(s, 1); /* temporary buffer that we use duing compression */
 
 	info->uncompressed_size = size;
 	if(compress((Bytef*)compdata, &s, (Bytef*)data, size) != Z_OK)
@@ -444,6 +461,22 @@ int datafile_add_data(DATAFILE_OUT *df, int size, void *data)
 	return df->num_datas-1;
 }
 
+int datafile_add_data_swapped(DATAFILE_OUT *df, int size, void *data)
+{
+#if defined(CONF_ARCH_ENDIAN_BIG)
+	void *swapped = mem_alloc(size, 1); /* temporary buffer that we use duing compression */
+	int index;
+	mem_copy(swapped, data, size);
+	swap_endian(&swapped, sizeof(int), size/sizeof(int));
+	index = datafile_add_data(df, size, swapped);
+	mem_free(swapped);
+	return index;
+#else
+	return datafile_add_data(df, size, data);
+#endif
+}
+
+
 int datafile_finish(DATAFILE_OUT *df)
 {
 	int itemsize = 0;