source: cpp/common/virtfile/stdiofile.h @ 1300

Last change on this file since 1300 was 820, checked in by Maciej Komosinski, 6 years ago

More complete implementation of directories in the virtual filesystem for Android

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#ifndef _STDIOFILE_H_
6#define _STDIOFILE_H_
7
8#include "virtfile.h"
9#include <common/nonstd_stdio.h>
10#include <common/nonstd_dir.h>
11
12class StdioFileSystem : public VirtFileSystem
13{
14public:
15        VirtFILE *Vfopen(const char *path, const char *mode);
16        bool Vfexists(const char* path);
17        VirtDIR *Vopendir(const char* path);
18        bool Vmkdir(const char* path) { return makeDirectory(path); }
19        bool Vdirexists(const char* path, bool is_writable);
20};
21
22#ifdef USE_MFILE
23class StdioFILE : public VirtFILE
24{
25protected:
26        MFILE *file;
27public:
28        StdioFILE(MFILE *f) :VirtFILE("") { file = f; }
29        StdioFILE(MFILE *f, const char* p) :VirtFILE(p) { file = f; }
30#ifndef NO_STD_IN_OUT_ERR
31        static void setStdio();
32#endif
33        size_t Vread(void *ptr, size_t size, size_t nmemb) { return mfread(ptr, size, nmemb, file); }
34        size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return mfwrite(ptr, size, nmemb, file); }
35        int Veof() { return mfeof(file); }
36        int Vputs(const char *s) { return mfputs(s, file); }
37        char *Vgets(char *s, int size) { return mfgets(s, size, file); }
38        int Vseek(long offset, int whence) { return mfseek(file, offset, whence); }
39        long Vtell() { return mftell(file); }
40        int Vflush() { return 0; /*NOT IMPLEMENTED!*/ }
41
42        ~StdioFILE() { if (file) mfclose(file); }
43};
44#else
45class StdioFILE : public VirtFILE
46{
47protected:
48        FILE *file;
49public:
50        StdioFILE(FILE *f) :VirtFILE("") { file = f; }
51        StdioFILE(FILE *f, const char* p) :VirtFILE(p) { file = f; }
52#ifndef NO_STD_IN_OUT_ERR
53        static void setStdio();
54#endif
55        size_t Vread(void *ptr, size_t size, size_t nmemb) { return fread(ptr, size, nmemb, file); }
56        size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return fwrite(ptr, size, nmemb, file); }
57        int Veof() { return feof(file); }
58        int Vputc(int c) { return fputc(c, file); }
59        int Vputs(const char *s) { return fputs(s, file); }
60        int Vgetc() { return fgetc(file); }
61        char *Vgets(char *s, int size) { return fgets(s, size, file); }
62        int Vprintf(const char *format, va_list args) { return vfprintf(file, format, args); }
63        int Vseek(long offset, int whence) { return fseek(file, offset, whence); }
64        long Vtell() { return ftell(file); }
65        void Vrewind() { rewind(file); }
66        int Vflush() { return fflush(file); }
67
68        ~StdioFILE() { if (file) fclose(file); }
69};
70#endif
71
72
73#ifdef _WIN32
74#ifdef __BORLANDC__
75typedef wDIR DIRTYPE;
76#else
77typedef WDIR DIRTYPE;
78#endif
79#else
80typedef DIR DIRTYPE;
81#endif
82
83class StdioDIR : public VirtDIR
84{
85        DIRTYPE *dir;
86#ifdef _WIN32
87        dirent de; //only used to convert wide string names (wdirent) to utf8 (dirent)
88#endif
89public:
90        StdioDIR(DIRTYPE *d) : dir(d) {}
91        ~StdioDIR()
92        {
93#ifdef _WIN32
94                if (dir) wclosedir(dir);
95#else
96                if (dir) closedir(dir);
97#endif
98        }
99        dirent* Vreaddir();
100};
101
102class StdioFILEDontClose : public StdioFILE
103{
104public:
105#ifdef USE_MFILE
106        StdioFILEDontClose(MFILE *f) : StdioFILE(f) {}
107#else
108        StdioFILEDontClose(FILE *f) : StdioFILE(f) {}
109#endif
110        ~StdioFILEDontClose() { file = 0; }
111};
112
113class StdioFileSystem_autoselect : public StdioFileSystem
114{
115public:
116        StdioFileSystem_autoselect()
117        {
118                VirtFILE::selectFileSystem(this);
119        }
120};
121
122#endif
Note: See TracBrowser for help on using the repository browser.