diff dmfile.c @ 0:32250b436bca

Initial re-import.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Sep 2012 01:54:23 +0300
parents
children d0257d0004f6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmfile.c	Fri Sep 28 01:54:23 2012 +0300
@@ -0,0 +1,46 @@
+/*
+ * DMLib
+ * -- Plain STDIO file endianess functions
+ * Programmed and designed by Matti 'ccr' Hamalainen
+ * (C) Copyright 2011 Tecnic Software productions (TNSP)
+ */
+#include "dmfile.h"
+
+
+BOOL dm_fread_str(FILE *f, void *buf, size_t len)
+{
+    return fread(buf, len, 1, f) == 1;
+}
+
+
+#define DM_DEFINE_FFUNC(xname, xtype, xmacro)         \
+BOOL dm_fread_ ## xname (FILE *f, xtype *v) {         \
+    xtype result;                                     \
+    if (fread(&result, sizeof( xtype ), 1, f) != 1)   \
+        return FALSE;                                 \
+    *v = DM_ ## xmacro ## _TO_NATIVE (result);        \
+    return TRUE;                                      \
+}
+
+#include "dmfiletmpl.h"
+
+
+#undef DM_DEFINE_FFUNC
+
+BOOL dm_fwrite_str(FILE *f, void *buf, size_t len)
+{
+    return fwrite(buf, len, 1, f) == 1;
+}
+
+
+#define DM_DEFINE_FFUNC(xname, xtype, xmacro)         \
+BOOL dm_fwrite_ ## xname (FILE *f, xtype v) {         \
+    xtype result = DM_NATIVE_TO_ ## xmacro (v);       \
+    if (fwrite(&result, sizeof( xtype ), 1, f) != 1)  \
+        return FALSE;                                 \
+    return TRUE;                                      \
+}
+
+#include "dmfiletmpl.h"
+
+#undef DM_DEFINE_FFUNC