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

Last change on this file since 955 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
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[820]2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[109]4
5#ifndef _STDIOFILE_H_
6#define _STDIOFILE_H_
7
8#include "virtfile.h"
[206]9#include <common/nonstd_stdio.h>
[109]10#include <common/nonstd_dir.h>
11
[281]12class StdioFileSystem : public VirtFileSystem
[109]13{
14public:
[281]15        VirtFILE *Vfopen(const char *path, const char *mode);
[295]16        bool Vfexists(const char* path);
[281]17        VirtDIR *Vopendir(const char* path);
[295]18        bool Vmkdir(const char* path) { return makeDirectory(path); }
[820]19        bool Vdirexists(const char* path, bool is_writable);
[109]20};
21
[206]22#ifdef USE_MFILE
[281]23class StdioFILE : public VirtFILE
[109]24{
[281]25protected:
26        MFILE *file;
27public:
[820]28        StdioFILE(MFILE *f) :VirtFILE("") { file = f; }
29        StdioFILE(MFILE *f, const char* p) :VirtFILE(p) { file = f; }
[425]30#ifndef NO_STD_IN_OUT_ERR
[281]31        static void setStdio();
[425]32#endif
[281]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!*/ }
[206]41
[281]42        ~StdioFILE() { if (file) mfclose(file); }
[206]43};
44#else
[281]45class StdioFILE : public VirtFILE
[206]46{
[281]47protected:
48        FILE *file;
49public:
[820]50        StdioFILE(FILE *f) :VirtFILE("") { file = f; }
51        StdioFILE(FILE *f, const char* p) :VirtFILE(p) { file = f; }
[425]52#ifndef NO_STD_IN_OUT_ERR
[281]53        static void setStdio();
[425]54#endif
[281]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); }
[109]67
[281]68        ~StdioFILE() { if (file) fclose(file); }
[109]69};
[206]70#endif
[109]71
[281]72
73#ifdef _WIN32
74#ifdef __BORLANDC__
[820]75typedef wDIR DIRTYPE;
[281]76#else
[820]77typedef WDIR DIRTYPE;
[281]78#endif
79#else
[820]80typedef DIR DIRTYPE;
[281]81#endif
82
83class StdioDIR : public VirtDIR
[109]84{
[281]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();
[109]100};
101
[281]102class StdioFILEDontClose : public StdioFILE
[109]103{
[281]104public:
[206]105#ifdef USE_MFILE
[281]106        StdioFILEDontClose(MFILE *f) : StdioFILE(f) {}
[206]107#else
[281]108        StdioFILEDontClose(FILE *f) : StdioFILE(f) {}
[206]109#endif
[281]110        ~StdioFILEDontClose() { file = 0; }
[109]111};
112
[820]113class StdioFileSystem_autoselect : public StdioFileSystem
[299]114{
115public:
[820]116        StdioFileSystem_autoselect()
[299]117        {
[820]118                VirtFILE::selectFileSystem(this);
[299]119        }
120};
121
[109]122#endif
Note: See TracBrowser for help on using the repository browser.