12 #include "../../gfx.h"
14 #if GFX_USE_GFILE && GFILE_NEED_STRINGS
21 static int StringRead(
GFILE *f,
void *buf,
int size) {
28 p = ((
char *)f->obj) + f->pos;
29 for(res = 0; res < size && *p; res++, p++, buf = ((
char *)buf)+1)
30 ((
char *)buf)[0] = *p;
33 static int StringWrite(
GFILE *f,
const void *buf,
int size) {
37 if ((f->flags & GFILEFLG_APPEND)) {
38 while(((
char *)f->obj)[f->pos])
41 memcpy(((
char *)f->obj)+f->pos, buf, size);
42 ((
char *)f->obj)[f->pos+size] = 0;
46 static const GFILEVMT StringVMT = {
50 0, 0, StringRead, StringWrite,
53 #if GFILE_NEED_FILELISTS
58 static void gfileOpenStringFromStaticGFILE(
GFILE *f,
char *str) {
59 if ((f->flags & GFILEFLG_TRUNC) && str)
64 f->flags |= GFILEFLG_OPEN|GFILEFLG_CANSEEK;
71 if (!str || !(f = _gfileFindSlot(mode)))
75 gfileOpenStringFromStaticGFILE(f, str);
80 int snprintg(
char *buf,
int maxlen,
const char *fmt, ...) {
93 f.flags = GFILEFLG_WRITE|GFILEFLG_TRUNC;
94 gfileOpenStringFromStaticGFILE(&f, buf);
97 res = vfnprintg(&f, maxlen-1, fmt, ap);
101 int vsnprintg(
char *buf,
int maxlen,
const char *fmt, va_list arg) {
112 f.flags = GFILEFLG_WRITE|GFILEFLG_TRUNC;
113 gfileOpenStringFromStaticGFILE(&f, buf);
115 return vfnprintg(&f, maxlen-1, fmt, arg);
120 int sscang(
const char *buf,
const char *fmt, ...) {
125 f.flags = GFILEFLG_READ;
126 gfileOpenStringFromStaticGFILE(&f, (
char *)buf);
129 res = vfscang(&f, fmt, ap);
134 int vsscang(
const char *buf,
const char *fmt, va_list arg) {
137 f.flags = GFILEFLG_READ;
138 gfileOpenStringFromStaticGFILE(&f, (
char *)buf);
140 return vfscang(&f, fmt, arg);
GFILE file system header.
GFILE * gfileOpenString(char *str, const char *mode)
Open file from a null terminated C string.
struct GFILE GFILE
A file pointer.