diff options
| author | inmarket <andrewh@inmarket.com.au> | 2014-08-12 16:45:06 +1000 |
|---|---|---|
| committer | inmarket <andrewh@inmarket.com.au> | 2014-08-12 16:45:06 +1000 |
| commit | 5460a923ab25d27e522fe175563633665c477e02 (patch) | |
| tree | e43734965f66092d3d076a599b3b8a188b005bc0 /src/gfile/inc_strings.c | |
| parent | 0e74c164c3eac14f6e99d1a5cc4e0563faeff5d0 (diff) | |
| parent | 10902154aec652a3fcdf028b2c6ff16743464973 (diff) | |
| download | uGFX-5460a923ab25d27e522fe175563633665c477e02.tar.gz uGFX-5460a923ab25d27e522fe175563633665c477e02.tar.bz2 uGFX-5460a923ab25d27e522fe175563633665c477e02.zip | |
Merge branch 'master' into newmouse
Diffstat (limited to 'src/gfile/inc_strings.c')
| -rw-r--r-- | src/gfile/inc_strings.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/gfile/inc_strings.c b/src/gfile/inc_strings.c new file mode 100644 index 00000000..692d2dd3 --- /dev/null +++ b/src/gfile/inc_strings.c @@ -0,0 +1,69 @@ +/* + * 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 + */ + +/** + * This file is included by src/gfile/gfile.c + */ + +/******************************************************** + * The virtual string file VMT + ********************************************************/ + +#include <string.h> + +// Special String VMT +static int StringRead(GFILE *f, void *buf, int size) { + int res; + char *p; + + p = ((char *)f->obj) + f->pos; + for(res = 0; res < size && *p; res++, p++, buf = ((char *)buf)+1) + ((char *)buf)[0] = *p; + return res; +} +static int StringWrite(GFILE *f, const void *buf, int size) { + if ((f->flags & GFILEFLG_APPEND)) { + while(((char *)f->obj)[f->pos]) + f->pos++; + } + memcpy(((char *)f->obj)+f->pos, buf, size); + ((char *)f->obj)[f->pos+size] = 0; + return size; +} +static const GFILEVMT StringVMT = { + 0, // next + 0, // flags + '_', // prefix + 0, 0, 0, 0, + 0, 0, StringRead, StringWrite, + 0, 0, 0, + 0, 0, 0, + #if GFILE_NEED_FILELISTS + 0, 0, 0, + #endif +}; + +static void gfileOpenStringFromStaticGFILE(GFILE *f, char *str) { + if ((f->flags & GFILEFLG_TRUNC)) + str[0] = 0; + f->vmt = &StringVMT; + f->obj = str; + f->pos = 0; + f->flags |= GFILEFLG_OPEN|GFILEFLG_CANSEEK; +} + +GFILE *gfileOpenString(char *str, const char *mode) { + GFILE *f; + + // Get an empty file and set the flags + if (!(f = findemptyfile(mode))) + return 0; + + // File is open - fill in all the details + gfileOpenStringFromStaticGFILE(f, str); + return f; +} |
