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

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

Cygwin compatibility

  • Property svn:eol-style set to native
File size: 3.3 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#ifndef _VIRTFILE_H_
6#define _VIRTFILE_H_
7
8#include <stdio.h>
9#include <stdarg.h>
10#include <common/nonstd_dir.h>
11//#include <dirent.h> //to jest inkludowane przez powyzsze
12//struct dirent; //kiedys byla ta linia jak nie bylo jeszcze implementacji windowsowej dirent, ale borlandowi sie nie podoba jak s¹ obie
13
14#ifdef DLLEXPORTACTIVE  //tylko w tym pliku uzyte
15#define DLLEXP __declspec(dllexport)
16#else
17#define DLLEXP
18#endif
19
20class DLLEXP VirtFileSystem;
21
22class DLLEXP VirtFILE
23{
24  public:
25virtual int Vread(void *ptr, size_t size, size_t nmemb)=0;
26virtual int Vwrite(const void *ptr, size_t size, size_t nmemb)=0;
27virtual int Veof()=0;
28virtual int Vputc(int c)=0;
29virtual int Vputs(const char *s)=0;
30virtual int Vgetc()=0;
31virtual int Vseek(long offset, int whence)=0;
32virtual int Vtell()=0;
33virtual void Vrewind()=0;
34virtual int Vflush()=0;
35virtual char *Vgets(char *s, int size)=0;
36virtual int Vprintf(const char *format, va_list args)=0;
37int printf(const char *format, ...);
38virtual const char *VgetPath() {return 0;} // 0=unspecified path
39virtual ~VirtFILE();
40static VirtFILE *Vstdin,*Vstdout,*Vstderr;
41static void setVstdin(VirtFILE *);
42static void setVstdout(VirtFILE *);
43static void setVstderr(VirtFILE *);
44static VirtFILE* getVstdin();
45static VirtFILE* getVstdout();
46static VirtFILE* getVstderr();
47static VirtFileSystem *vfs;
48static void selectFileSystem(VirtFileSystem *s);
49};
50
51class DLLEXP VirtDIR
52{
53  public:
54virtual ~VirtDIR() {}
55virtual dirent* Vreaddir() {return 0;}
56};
57
58class DLLEXP VirtFileSystem
59{
60public:
61virtual VirtFILE *Vfopen(const char* path,const char*mode);
62virtual int Vfexists(const char* path);
63virtual VirtDIR *Vopendir(const char* path);
64};
65
66DLLEXP VirtFILE *Vfopen(const char* path,const char*mode);
67DLLEXP VirtDIR *Vopendir(const char* path);
68DLLEXP int Vfexists(const char* path);
69
70DLLEXP int fread(void *ptr, size_t size, size_t nmemb, VirtFILE* f);
71DLLEXP int fwrite(const void *ptr, size_t size, size_t nmemb, VirtFILE* f);
72
73
74//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.cpp
75#if defined __BORLANDC__ || defined _MSC_VER || defined __CYGWIN__ || defined SHP
76 #undef feof
77#endif
78 
79DLLEXP int feof(VirtFILE* f);// {return f->Veof();}
80
81//...and then restore the original macro:
82#ifdef __BORLANDC__
83 #define feof(__f)     ((__f)->flags & _F_EOF)
84#endif
85#ifdef _MSC_VER
86 #define feof(_stream)     ((_stream)->_flag & _IOEOF)
87#endif
88#ifdef __CYGWIN__
89 #define feof(p)  __sfeof(p)
90#endif
91#ifdef SHP
92 restore original macro... if you ever want to compile this code on bada
93#endif
94
95
96DLLEXP int fputc(int c,VirtFILE* f);
97DLLEXP int fputs(const char *s,VirtFILE* f);
98DLLEXP int fgetc(VirtFILE* f);
99DLLEXP int fseek(VirtFILE* f,long offset, int whence);
100DLLEXP int ftell(VirtFILE* f);
101DLLEXP void rewind(VirtFILE* f);
102DLLEXP int fflush(VirtFILE* f);
103DLLEXP char *fgets(char *s, int size, VirtFILE* f);
104DLLEXP int fprintf(VirtFILE* f,const char *format, ...);
105DLLEXP int fclose(VirtFILE* f);
106
107DLLEXP dirent* readdir(VirtDIR* d);
108DLLEXP int closedir(VirtDIR* d);
109
110#endif
111
Note: See TracBrowser for help on using the repository browser.