aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile/gfile_fs_mem.c
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-08-20 17:42:53 +1000
committerinmarket <andrewh@inmarket.com.au>2014-08-20 17:42:53 +1000
commit0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478 (patch)
tree3dc625e7dfcfc620e83827ccd18423be1b5334f4 /src/gfile/gfile_fs_mem.c
parentfcbb66a9394eaf4059bc942df6729b4b55a057d8 (diff)
downloaduGFX-0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478.tar.gz
uGFX-0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478.tar.bz2
uGFX-0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478.zip
Rename lots of files to help prevent compile time name conflicts.
Diffstat (limited to 'src/gfile/gfile_fs_mem.c')
-rw-r--r--src/gfile/gfile_fs_mem.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/gfile/gfile_fs_mem.c b/src/gfile/gfile_fs_mem.c
new file mode 100644
index 00000000..150220b8
--- /dev/null
+++ b/src/gfile/gfile_fs_mem.c
@@ -0,0 +1,65 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/********************************************************
+ * The virtual memory file-system
+ ********************************************************/
+
+#include "gfx.h"
+
+#if GFX_USE_GFILE && GFILE_NEED_MEMFS
+
+#include "gfile_fs.h"
+
+#include <string.h>
+
+static int MEMRead(GFILE *f, void *buf, int size);
+static int MEMWrite(GFILE *f, const void *buf, int size);
+static bool_t MEMSetpos(GFILE *f, long int pos);
+
+static const GFILEVMT FsMemVMT = {
+ GFSFLG_SEEKABLE|GFSFLG_WRITEABLE, // flags
+ 0, // prefix
+ 0, 0, 0, 0,
+ 0, 0, MEMRead, MEMWrite,
+ MEMSetpos, 0, 0,
+ 0, 0, 0,
+ #if GFILE_NEED_FILELISTS
+ 0, 0, 0,
+ #endif
+};
+
+static int MEMRead(GFILE *f, void *buf, int size) {
+ memcpy(buf, ((char *)f->obj)+f->pos, size);
+ return size;
+}
+static int MEMWrite(GFILE *f, const void *buf, int size) {
+ memcpy(((char *)f->obj)+f->pos, buf, size);
+ return size;
+}
+static bool_t MEMSetpos(GFILE *f, long int pos) {
+ (void) f;
+ (void) pos;
+ return TRUE;
+}
+
+GFILE * gfileOpenMemory(void *memptr, const char *mode) {
+ GFILE *f;
+
+ // Get an empty file and set the flags
+ if (!(f = _gfileFindSlot(mode)))
+ return 0;
+
+ // File is open - fill in all the details
+ f->vmt = &FsMemVMT;
+ f->obj = memptr;
+ f->pos = 0;
+ f->flags |= GFILEFLG_OPEN|GFILEFLG_CANSEEK;
+ return f;
+}
+
+#endif //GFX_USE_GFILE && GFILE_NEED_MEMFS