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

Last change on this file since 123 was 123, checked in by sz, 8 years ago

Cygwin compatibility

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
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
7VirtFILE *VirtFILE::Vstdin=0;
8VirtFILE *VirtFILE::Vstdout=0;
9VirtFILE *VirtFILE::Vstderr=0;
10
11VirtFileSystem *VirtFILE::vfs=0;
12
13VirtFILE *Vfopen(const char* path,const char*mode)
14{
15return VirtFILE::vfs ? VirtFILE::vfs->Vfopen(path,mode) : 0;
16}
17
18VirtDIR *Vopendir(const char* path)
19{
20return VirtFILE::vfs ? VirtFILE::vfs->Vopendir(path) : 0;
21}
22
23int Vfexists(const char* path)
24{
25return VirtFILE::vfs ? VirtFILE::vfs->Vfexists(path) : 0;
26}
27
28VirtFILE::~VirtFILE()
29{}
30
31void VirtFILE::selectFileSystem(VirtFileSystem *s) {vfs=s;}
32
33int VirtFILE::printf(const char *format, ...)
34{
35int ret; va_list argptr;
36va_start(argptr,format);
37ret=Vprintf(format,argptr);
38va_end(argptr);
39return ret;
40}
41
42void VirtFILE::setVstdin(VirtFILE *f) {Vstdin=f;}
43void VirtFILE::setVstdout(VirtFILE *f) {Vstdout=f;}
44void VirtFILE::setVstderr(VirtFILE *f) {Vstderr=f;}
45VirtFILE* VirtFILE::getVstdin() {return Vstdin;}
46VirtFILE* VirtFILE::getVstdout() {return Vstdout;}
47VirtFILE* VirtFILE::getVstderr() {return Vstderr;}
48//////////////////////////////////////////////////////////////////////////
49
50VirtFILE* VirtFileSystem::Vfopen(const char* path,const char*mode) {return 0;}
51int VirtFileSystem::Vfexists(const char* path) {return 0;}
52VirtDIR* VirtFileSystem::Vopendir(const char* path) {return 0;}
53
54//////////////////////////////////////////////////////////////////////////
55
56
57
58int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f) {return f->Vread(ptr,size,nmemb);}
59int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f) {return f->Vwrite(ptr,size,nmemb);}
60
61//for some systems, we need to #undef feof which is unfortunately defined as a macro... we have to #undef just to be able to define our own function with this name. Same in virtfile.h
62#if defined __BORLANDC__ || defined _MSC_VER || defined __CYGWIN__ || defined SHP
63 #undef feof
64#endif
65
66int feof(VirtFILE* f) {return f->Veof();}
67
68//...and then restore the original macro:
69#ifdef __BORLANDC__
70 #define feof(__f)     ((__f)->flags & _F_EOF)
71#endif
72#ifdef _MSC_VER
73 #define feof(_stream)     ((_stream)->_flag & _IOEOF)
74#endif
75#ifdef __CYGWIN__
76 #define feof(p)  __sfeof(p)
77#endif
78#ifdef SHP
79 restore original macro... if you ever want to compile this code on bada
80#endif
81
82
83int fputc(int c,VirtFILE* f) {return f->Vputc(c);}
84int fputs(const char *s,VirtFILE* f) {return f->Vputs(s);}
85int fgetc(VirtFILE* f) {return f->Vgetc();}
86int fseek(VirtFILE* f,long offset, int whence) {return f->Vseek(offset,whence);}
87int ftell(VirtFILE* f) {return f->Vtell();}
88void rewind(VirtFILE* f) {f->Vrewind();}
89int fflush(VirtFILE* f) {return f->Vflush();}
90char *fgets(char *s, int size, VirtFILE* f) {return f->Vgets(s,size);}
91int fprintf(VirtFILE* f,const char *format, ...)
92        {
93        int ret; va_list argptr;
94        va_start(argptr,format);
95        ret=f->Vprintf(format,argptr);
96        va_end(argptr);
97        return ret;
98        }
99int fclose(VirtFILE* f) {delete f; return 0;}
100
101int closedir(VirtDIR* d) {delete d; return 0;}
102dirent* readdir(VirtDIR* d) {return d->Vreaddir();}
103
Note: See TracBrowser for help on using the repository browser.