- Timestamp:
- 04/03/14 01:24:30 (11 years ago)
- Location:
- cpp/frams/virtfile
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/virtfile/stdiofile.cpp
r197 r206 11 11 { 12 12 //printFM("Vfopen %s %s",path,mode); 13 #ifdef USE_MFILE 14 MFILE *f=mfopen(path,mode); 15 #else 13 16 FILE *f=fopen(path,mode); 17 #endif 14 18 //printFM("%p",f); 15 19 if (f) return new StdioFILE(f,path); else return 0; -
cpp/frams/virtfile/stdiofile.h
r197 r206 8 8 #include "virtfile.h" 9 9 #include <frams/util/sstring.h> 10 #ifdef USE_MFILE 11 #include <common/nonstd_stdio.h> 12 #else 10 13 #include <stdio.h> 14 #endif 11 15 #include <common/nonstd_dir.h> 12 16 … … 19 23 }; 20 24 25 #ifdef USE_MFILE 26 class StdioFILE: public VirtFILE 27 { 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 int Vread(void *ptr, size_t size, size_t nmemb) {return mfread(ptr,size,nmemb,file);} 36 int 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 int Vtell() {return mftell(file);} 42 int Vflush() {return 0;/*NOT IMPLEMENTED!*/;} 43 const char* VgetPath() {return path;} 44 45 ~StdioFILE() {if (file) fclose(file);} 46 }; 47 #else 21 48 class StdioFILE: public VirtFILE 22 49 { … … 44 71 ~StdioFILE() {if (file) fclose(file);} 45 72 }; 73 #endif 46 74 47 75 class StdioDIR: public VirtDIR … … 57 85 { 58 86 public: 87 #ifdef USE_MFILE 88 StdioFILEDontClose(MFILE *f):StdioFILE(f) {} 89 #else 59 90 StdioFILEDontClose(FILE *f):StdioFILE(f) {} 91 #endif 60 92 ~StdioFILEDontClose() {file=0;} 61 93 }; -
cpp/frams/virtfile/virtfile.cpp
r197 r206 4 4 5 5 #include "virtfile.h" 6 #include <common/stl-util.h> 6 7 7 8 VirtFILE *VirtFILE::Vstdin=0; … … 30 31 31 32 void VirtFILE::selectFileSystem(VirtFileSystem *s) {vfs=s;} 33 34 int VirtFILE::Vprintf(const char *format, va_list args) 35 { 36 string s=ssprintf_va(format,args); 37 return Vwrite(s.c_str(),1,s.size()); 38 } 32 39 33 40 int VirtFILE::printf(const char *format, ...) -
cpp/frams/virtfile/virtfile.h
r197 r206 26 26 virtual int Vwrite(const void *ptr, size_t size, size_t nmemb)=0; 27 27 virtual int Veof()=0; 28 virtual int Vputc(int c) =0;28 virtual int Vputc(int c) {unsigned char data=c; return (Vwrite(&data,1,1)==1)?data:EOF;} 29 29 virtual int Vputs(const char *s)=0; 30 virtual int Vgetc() =0;30 virtual int Vgetc() {unsigned char data; if (Vread(&data,1,1)==1) return data; else return EOF;} 31 31 virtual int Vseek(long offset, int whence)=0; 32 32 virtual int Vtell()=0; 33 virtual void Vrewind() =0;33 virtual void Vrewind() {Vseek(0,SEEK_SET);} 34 34 virtual int Vflush()=0; 35 35 virtual char *Vgets(char *s, int size)=0; 36 virtual int Vprintf(const char *format, va_list args) =0;36 virtual int Vprintf(const char *format, va_list args); 37 37 int printf(const char *format, ...); 38 38 virtual const char *VgetPath() {return 0;} // 0=unspecified path
Note: See TracChangeset
for help on using the changeset viewer.