source: cpp/frams/virtfile/virtfile.cpp @ 247

Last change on this file since 247 was 247, checked in by Maciej Komosinski, 10 years ago

Sources support both 32-bit and 64-bit, and more compilers

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 1999-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#include <common/stl-util.h>
7
8VirtFILE *VirtFILE::Vstdin=0;
9VirtFILE *VirtFILE::Vstdout=0;
10VirtFILE *VirtFILE::Vstderr=0;
11
12VirtFileSystem *VirtFILE::vfs=0;
13
14VirtFILE *Vfopen(const char* path,const char*mode)
15{
16return VirtFILE::vfs ? VirtFILE::vfs->Vfopen(path,mode) : 0;
17}
18
19VirtDIR *Vopendir(const char* path)
20{
21return VirtFILE::vfs ? VirtFILE::vfs->Vopendir(path) : 0;
22}
23
24int Vfexists(const char* path)
25{
26return VirtFILE::vfs ? VirtFILE::vfs->Vfexists(path) : 0;
27}
28
29VirtFILE::~VirtFILE()
30{}
31
32void VirtFILE::selectFileSystem(VirtFileSystem *s) {vfs=s;}
33
34int VirtFILE::Vprintf(const char *format, va_list args)
35{
36string s=ssprintf_va(format,args);
37return Vwrite(s.c_str(),1,s.size());
38}
39
40int VirtFILE::printf(const char *format, ...)
41{
42int ret; va_list argptr;
43va_start(argptr,format);
44ret=Vprintf(format,argptr);
45va_end(argptr);
46return ret;
47}
48
49int VirtFILE::getSize()
50{
51  int saved_pos = Vtell();
52  Vseek(0, SEEK_END);
53  int size = Vtell();
54  Vseek(saved_pos, SEEK_SET);
55  return size;
56}
57
58void VirtFILE::setVstdin(VirtFILE *f) {Vstdin=f;}
59void VirtFILE::setVstdout(VirtFILE *f) {Vstdout=f;}
60void VirtFILE::setVstderr(VirtFILE *f) {Vstderr=f;}
61VirtFILE* VirtFILE::getVstdin() {return Vstdin;}
62VirtFILE* VirtFILE::getVstdout() {return Vstdout;}
63VirtFILE* VirtFILE::getVstderr() {return Vstderr;}
64//////////////////////////////////////////////////////////////////////////
65
66VirtFILE* VirtFileSystem::Vfopen(const char* path,const char*mode) {return 0;}
67int VirtFileSystem::Vfexists(const char* path) {return 0;}
68VirtDIR* VirtFileSystem::Vopendir(const char* path) {return 0;}
69
70//////////////////////////////////////////////////////////////////////////
71
72
73
74int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f) {return f->Vread(ptr,size,nmemb);}
75int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f) {return f->Vwrite(ptr,size,nmemb);}
76
77
78//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
79#if defined _MSC_VER || defined __CYGWIN__ || defined SHP || defined __ANDROID__
80 #pragma push_macro("feof")
81 #undef feof
82#endif
83#if defined __BORLANDC__ //does not support #pragma push_macro/pop_macro
84 #undef feof
85#endif
86
87int feof(VirtFILE* f) {return f->Veof();}
88
89//...and then restore the original macro:
90#if defined _MSC_VER || defined __CYGWIN__ || defined SHP || defined __ANDROID__
91 #pragma pop_macro("feof")
92#endif
93#if defined __BORLANDC__
94 #define feof(__f)     ((__f)->flags & _F_EOF)
95#endif
96
97
98int fputc(int c,VirtFILE* f) {return f->Vputc(c);}
99int fputs(const char *s,VirtFILE* f) {return f->Vputs(s);}
100int fgetc(VirtFILE* f) {return f->Vgetc();}
101int fseek(VirtFILE* f,long offset, int whence) {return f->Vseek(offset,whence);}
102int ftell(VirtFILE* f) {return f->Vtell();}
103void rewind(VirtFILE* f) {f->Vrewind();}
104int fflush(VirtFILE* f) {return f->Vflush();}
105char *fgets(char *s, int size, VirtFILE* f) {return f->Vgets(s,size);}
106int fprintf(VirtFILE* f,const char *format, ...)
107        {
108        int ret; va_list argptr;
109        va_start(argptr,format);
110        ret=f->Vprintf(format,argptr);
111        va_end(argptr);
112        return ret;
113        }
114int fclose(VirtFILE* f) {delete f; return 0;}
115
116int closedir(VirtDIR* d) {delete d; return 0;}
117dirent* readdir(VirtDIR* d) {return d->Vreaddir();}
118
Note: See TracBrowser for help on using the repository browser.