1 | // This file is a part of the Framsticks GDK. |
---|
2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.framsticks.com/ for further information. |
---|
4 | |
---|
5 | #include "virtfile.h" |
---|
6 | |
---|
7 | VirtFILE *VirtFILE::Vstdin=0; |
---|
8 | VirtFILE *VirtFILE::Vstdout=0; |
---|
9 | VirtFILE *VirtFILE::Vstderr=0; |
---|
10 | |
---|
11 | VirtFileSystem *VirtFILE::vfs=0; |
---|
12 | |
---|
13 | VirtFILE *Vfopen(const char* path,const char*mode) |
---|
14 | { |
---|
15 | return VirtFILE::vfs ? VirtFILE::vfs->Vfopen(path,mode) : 0; |
---|
16 | } |
---|
17 | |
---|
18 | VirtDIR *Vopendir(const char* path) |
---|
19 | { |
---|
20 | return VirtFILE::vfs ? VirtFILE::vfs->Vopendir(path) : 0; |
---|
21 | } |
---|
22 | |
---|
23 | int Vfexists(const char* path) |
---|
24 | { |
---|
25 | return VirtFILE::vfs ? VirtFILE::vfs->Vfexists(path) : 0; |
---|
26 | } |
---|
27 | |
---|
28 | VirtFILE::~VirtFILE() |
---|
29 | {} |
---|
30 | |
---|
31 | void VirtFILE::selectFileSystem(VirtFileSystem *s) {vfs=s;} |
---|
32 | |
---|
33 | int VirtFILE::printf(const char *format, ...) |
---|
34 | { |
---|
35 | int ret; va_list argptr; |
---|
36 | va_start(argptr,format); |
---|
37 | ret=Vprintf(format,argptr); |
---|
38 | va_end(argptr); |
---|
39 | return ret; |
---|
40 | } |
---|
41 | |
---|
42 | void VirtFILE::setVstdin(VirtFILE *f) {Vstdin=f;} |
---|
43 | void VirtFILE::setVstdout(VirtFILE *f) {Vstdout=f;} |
---|
44 | void VirtFILE::setVstderr(VirtFILE *f) {Vstderr=f;} |
---|
45 | VirtFILE* VirtFILE::getVstdin() {return Vstdin;} |
---|
46 | VirtFILE* VirtFILE::getVstdout() {return Vstdout;} |
---|
47 | VirtFILE* VirtFILE::getVstderr() {return Vstderr;} |
---|
48 | ////////////////////////////////////////////////////////////////////////// |
---|
49 | |
---|
50 | VirtFILE* VirtFileSystem::Vfopen(const char* path,const char*mode) {return 0;} |
---|
51 | int VirtFileSystem::Vfexists(const char* path) {return 0;} |
---|
52 | VirtDIR* VirtFileSystem::Vopendir(const char* path) {return 0;} |
---|
53 | |
---|
54 | ////////////////////////////////////////////////////////////////////////// |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f) {return f->Vread(ptr,size,nmemb);} |
---|
59 | int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f) {return f->Vwrite(ptr,size,nmemb);} |
---|
60 | |
---|
61 | |
---|
62 | //since we want our own feof(VirtFILE*) function and some systems unfortunately define feof as a macro, we need to #undef it. Same as in virtfile.h |
---|
63 | #if defined _MSC_VER || defined __CYGWIN__ || defined SHP |
---|
64 | #pragma push_macro("feof") |
---|
65 | #undef feof |
---|
66 | #endif |
---|
67 | #if defined __BORLANDC__ //does not support #pragma push_macro/pop_macro |
---|
68 | #undef feof |
---|
69 | #endif |
---|
70 | |
---|
71 | int feof(VirtFILE* f) {return f->Veof();} |
---|
72 | |
---|
73 | //...and then restore the original macro: |
---|
74 | #if defined _MSC_VER || defined __CYGWIN__ || defined SHP |
---|
75 | #pragma pop_macro("feof") |
---|
76 | #endif |
---|
77 | #ifdef __BORLANDC__ |
---|
78 | #define feof(__f) ((__f)->flags & _F_EOF) |
---|
79 | #endif |
---|
80 | |
---|
81 | |
---|
82 | int fputc(int c,VirtFILE* f) {return f->Vputc(c);} |
---|
83 | int fputs(const char *s,VirtFILE* f) {return f->Vputs(s);} |
---|
84 | int fgetc(VirtFILE* f) {return f->Vgetc();} |
---|
85 | int fseek(VirtFILE* f,long offset, int whence) {return f->Vseek(offset,whence);} |
---|
86 | int ftell(VirtFILE* f) {return f->Vtell();} |
---|
87 | void rewind(VirtFILE* f) {f->Vrewind();} |
---|
88 | int fflush(VirtFILE* f) {return f->Vflush();} |
---|
89 | char *fgets(char *s, int size, VirtFILE* f) {return f->Vgets(s,size);} |
---|
90 | int fprintf(VirtFILE* f,const char *format, ...) |
---|
91 | { |
---|
92 | int ret; va_list argptr; |
---|
93 | va_start(argptr,format); |
---|
94 | ret=f->Vprintf(format,argptr); |
---|
95 | va_end(argptr); |
---|
96 | return ret; |
---|
97 | } |
---|
98 | int fclose(VirtFILE* f) {delete f; return 0;} |
---|
99 | |
---|
100 | int closedir(VirtDIR* d) {delete d; return 0;} |
---|
101 | dirent* readdir(VirtDIR* d) {return d->Vreaddir();} |
---|
102 | |
---|