- Timestamp:
- 12/27/14 01:01:43 (10 years ago)
- Location:
- cpp/frams/virtfile
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/virtfile/stdiofile.cpp
r227 r281 7 7 #include <common/nonstd_stdio.h> 8 8 #include <common/framsg.h> 9 #include <common/Convert.h> 9 10 10 VirtFILE* StdioFileSystem::Vfopen(const char * path,const char*mode)11 VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode) 11 12 { 12 13 //printFM("Vfopen %s %s",path,mode); 13 14 #ifdef USE_MFILE 14 MFILE *f =mfopen(path,mode);15 MFILE *f = mfopen(path, mode); 15 16 #else 16 FILE *f=fopen(path,mode); 17 #ifdef _WIN32 18 FILE *f = _wfopen(Convert::utf8ToUtf16(path).c_str(), Convert::strTOwstr(mode).c_str()); 19 #else 20 FILE *f = fopen(path, mode); 21 #endif 17 22 #endif 18 23 //printFM("%p",f); 19 if (f) return new StdioFILE(f, path); else return 0;24 if (f) return new StdioFILE(f, path); else return 0; 20 25 } 21 26 … … 23 28 { 24 29 //printFM("Vopendir %s",path); 25 DIR *d=opendir(path); 30 #ifdef _WIN32 31 DIRTYPE *d = wopendir(Convert::utf8ToUtf16(path).c_str()); 32 #else 33 DIR *d = opendir(path); 34 #endif 26 35 //printFM("%p",d); 27 36 if (d) return new StdioDIR(d); else return 0; … … 48 57 { 49 58 //printFM("Vreaddir %s",dir); 59 #ifdef _WIN32 60 wdirent *wde=wreaddir(dir); 61 if (wde==NULL) return NULL; 62 strcpy(de.d_name, Convert::wstrToUtf8(wde->d_name).c_str()); 63 return &de; 64 #else 50 65 return readdir(dir); 66 #endif 51 67 } -
cpp/frams/virtfile/stdiofile.h
r247 r281 15 15 #include <common/nonstd_dir.h> 16 16 17 class StdioFileSystem : public VirtFileSystem17 class StdioFileSystem : public VirtFileSystem 18 18 { 19 19 public: 20 VirtFILE *Vfopen(const char* path,const char*mode);21 int Vfexists(const char* path);22 VirtDIR *Vopendir(const char* path);20 VirtFILE *Vfopen(const char *path, const char *mode); 21 int Vfexists(const char* path); 22 VirtDIR *Vopendir(const char* path); 23 23 }; 24 24 25 25 #ifdef USE_MFILE 26 class StdioFILE : public VirtFILE26 class StdioFILE : public VirtFILE 27 27 { 28 29 MFILE *file;30 SString path;31 32 StdioFILE(MFILE *f) {file=f;}33 StdioFILE(MFILE *f,const SString& p) {file=f;path=p;}34 static void setStdio();35 size_t Vread(void *ptr, size_t size, size_t nmemb) {return mfread(ptr,size,nmemb,file);}36 size_t Vwrite(const void *ptr, size_t size, size_t nmemb) {return mfwrite(ptr,size,nmemb,file);}37 int Veof() {return mfeof(file);}38 int Vputs(const char *s) {return mfputs(s,file);}39 char *Vgets(char *s, int size) {return mfgets(s,size,file);}40 int Vseek(long offset, int whence) {return mfseek(file,offset,whence);}41 long Vtell() {return mftell(file);}42 int Vflush() {return 0;/*NOT IMPLEMENTED!*/;}43 const char* VgetPath() {return path;}28 protected: 29 MFILE *file; 30 SString path; 31 public: 32 StdioFILE(MFILE *f) { file = f; } 33 StdioFILE(MFILE *f, const SString& p) { file = f; path = p; } 34 static void setStdio(); 35 size_t Vread(void *ptr, size_t size, size_t nmemb) { return mfread(ptr, size, nmemb, file); } 36 size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return mfwrite(ptr, size, nmemb, file); } 37 int Veof() { return mfeof(file); } 38 int Vputs(const char *s) { return mfputs(s, file); } 39 char *Vgets(char *s, int size) { return mfgets(s, size, file); } 40 int Vseek(long offset, int whence) { return mfseek(file, offset, whence); } 41 long Vtell() { return mftell(file); } 42 int Vflush() { return 0; /*NOT IMPLEMENTED!*/ } 43 const char* VgetPath() { return path; } 44 44 45 ~StdioFILE() {if (file) mfclose(file);}45 ~StdioFILE() { if (file) mfclose(file); } 46 46 }; 47 47 #else 48 class StdioFILE : public VirtFILE48 class StdioFILE : public VirtFILE 49 49 { 50 51 FILE *file;52 SString path;53 54 StdioFILE(FILE *f) {file=f;}55 StdioFILE(FILE *f,const SString& p) {file=f;path=p;}56 static void setStdio();57 size_t Vread(void *ptr, size_t size, size_t nmemb) {return fread(ptr,size,nmemb,file);}58 size_t Vwrite(const void *ptr, size_t size, size_t nmemb) {return fwrite(ptr,size,nmemb,file);}59 int Veof() {return feof(file);}60 int Vputc(int c) {return fputc(c,file);}61 int Vputs(const char *s) {return fputs(s,file);}62 int Vgetc() {return fgetc(file);}63 char *Vgets(char *s, int size) {return fgets(s,size,file);}64 int Vprintf(const char *format, va_list args) { return vfprintf(file,format,args); }65 int Vseek(long offset, int whence) {return fseek(file,offset,whence);}66 long Vtell() {return ftell(file);}67 void Vrewind() {rewind(file);}68 int Vflush() {return fflush(file);}69 const char* VgetPath() {return path;}50 protected: 51 FILE *file; 52 SString path; 53 public: 54 StdioFILE(FILE *f) { file = f; } 55 StdioFILE(FILE *f, const SString& p) { file = f; path = p; } 56 static void setStdio(); 57 size_t Vread(void *ptr, size_t size, size_t nmemb) { return fread(ptr, size, nmemb, file); } 58 size_t Vwrite(const void *ptr, size_t size, size_t nmemb) { return fwrite(ptr, size, nmemb, file); } 59 int Veof() { return feof(file); } 60 int Vputc(int c) { return fputc(c, file); } 61 int Vputs(const char *s) { return fputs(s, file); } 62 int Vgetc() { return fgetc(file); } 63 char *Vgets(char *s, int size) { return fgets(s, size, file); } 64 int Vprintf(const char *format, va_list args) { return vfprintf(file, format, args); } 65 int Vseek(long offset, int whence) { return fseek(file, offset, whence); } 66 long Vtell() { return ftell(file); } 67 void Vrewind() { rewind(file); } 68 int Vflush() { return fflush(file); } 69 const char* VgetPath() { return path; } 70 70 71 ~StdioFILE() {if (file) fclose(file);}71 ~StdioFILE() { if (file) fclose(file); } 72 72 }; 73 73 #endif 74 74 75 class StdioDIR: public VirtDIR 75 76 #ifdef _WIN32 77 #ifdef __BORLANDC__ 78 typedef wDIR DIRTYPE; 79 #else 80 typedef WDIR DIRTYPE; 81 #endif 82 #else 83 typedef DIR DIRTYPE; 84 #endif 85 86 class StdioDIR : public VirtDIR 76 87 { 77 DIR *dir; 78 public: 79 StdioDIR(DIR* d):dir(d) {} 80 ~StdioDIR() {if (dir) closedir(dir);} 81 dirent* Vreaddir(); 88 DIRTYPE *dir; 89 #ifdef _WIN32 90 dirent de; //only used to convert wide string names (wdirent) to utf8 (dirent) 91 #endif 92 public: 93 StdioDIR(DIRTYPE *d) : dir(d) {} 94 ~StdioDIR() 95 { 96 #ifdef _WIN32 97 if (dir) wclosedir(dir); 98 #else 99 if (dir) closedir(dir); 100 #endif 101 } 102 dirent* Vreaddir(); 82 103 }; 83 104 84 class StdioFILEDontClose : public StdioFILE105 class StdioFILEDontClose : public StdioFILE 85 106 { 86 107 public: 87 108 #ifdef USE_MFILE 88 StdioFILEDontClose(MFILE *f):StdioFILE(f) {}109 StdioFILEDontClose(MFILE *f) : StdioFILE(f) {} 89 110 #else 90 StdioFILEDontClose(FILE *f):StdioFILE(f) {}111 StdioFILEDontClose(FILE *f) : StdioFILE(f) {} 91 112 #endif 92 ~StdioFILEDontClose() {file=0;}113 ~StdioFILEDontClose() { file = 0; } 93 114 }; 94 115 95 116 #endif 117
Note: See TracChangeset
for help on using the changeset viewer.