[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
| 2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
| 3 | // See LICENSE.txt for details. |
---|
[109] | 4 | |
---|
| 5 | #include "stdiofile.h" |
---|
| 6 | #include <common/nonstd_dir.h> |
---|
| 7 | #include <common/nonstd_stdio.h> |
---|
[372] | 8 | #include <common/hmessage.h> |
---|
[281] | 9 | #include <common/Convert.h> |
---|
[109] | 10 | |
---|
[281] | 11 | VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode) |
---|
[109] | 12 | { |
---|
[372] | 13 | //printH("Vfopen %s %s",path,mode); |
---|
[374] | 14 | #if defined USE_MFILE || defined _WIN32 |
---|
[281] | 15 | MFILE *f = mfopen(path, mode); |
---|
[206] | 16 | #else |
---|
[281] | 17 | FILE *f = fopen(path, mode); |
---|
[206] | 18 | #endif |
---|
[372] | 19 | //printH("%p",f); |
---|
[298] | 20 | if (f) return new StdioFILE(f, path); else return NULL; |
---|
[109] | 21 | } |
---|
| 22 | |
---|
| 23 | VirtDIR* StdioFileSystem::Vopendir(const char* path) |
---|
| 24 | { |
---|
[372] | 25 | //printH("Vopendir %s",path); |
---|
[281] | 26 | #ifdef _WIN32 |
---|
| 27 | DIRTYPE *d = wopendir(Convert::utf8ToUtf16(path).c_str()); |
---|
| 28 | #else |
---|
| 29 | DIR *d = opendir(path); |
---|
| 30 | #endif |
---|
[372] | 31 | //printH("%p",d); |
---|
[298] | 32 | if (d) return new StdioDIR(d); else return NULL; |
---|
[109] | 33 | } |
---|
| 34 | |
---|
[295] | 35 | bool StdioFileSystem::Vfexists(const char* path) |
---|
[109] | 36 | { |
---|
| 37 | return fileExists(path); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | void StdioFILE::setStdio() |
---|
| 41 | { |
---|
[227] | 42 | #ifndef NO_STD_IN_OUT_ERR |
---|
[109] | 43 | static StdioFILEDontClose si(stdin); |
---|
| 44 | static StdioFILEDontClose so(stdout); |
---|
| 45 | static StdioFILEDontClose se(stderr); |
---|
| 46 | setVstdin(&si); |
---|
| 47 | setVstdout(&so); |
---|
| 48 | setVstderr(&se); |
---|
[227] | 49 | #endif |
---|
[109] | 50 | } |
---|
| 51 | |
---|
| 52 | dirent* StdioDIR::Vreaddir() |
---|
| 53 | { |
---|
[372] | 54 | //printH("Vreaddir %s",dir); |
---|
[281] | 55 | #ifdef _WIN32 |
---|
| 56 | wdirent *wde=wreaddir(dir); |
---|
| 57 | if (wde==NULL) return NULL; |
---|
| 58 | strcpy(de.d_name, Convert::wstrToUtf8(wde->d_name).c_str()); |
---|
| 59 | return &de; |
---|
| 60 | #else |
---|
[109] | 61 | return readdir(dir); |
---|
[281] | 62 | #endif |
---|
[109] | 63 | } |
---|