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. |
---|
4 | |
---|
5 | #include "stdiofile.h" |
---|
6 | #include <common/nonstd_dir.h> |
---|
7 | #include <common/nonstd_stdio.h> |
---|
8 | #include <common/framsg.h> |
---|
9 | #include <common/Convert.h> |
---|
10 | |
---|
11 | VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode) |
---|
12 | { |
---|
13 | //printFM("Vfopen %s %s",path,mode); |
---|
14 | #ifdef _WIN32 |
---|
15 | FILE *f = _wfopen(Convert::utf8ToUtf16(path).c_str(), Convert::strTOwstr(mode).c_str()); |
---|
16 | #else |
---|
17 | #ifdef USE_MFILE |
---|
18 | MFILE *f = mfopen(path, mode); |
---|
19 | #else |
---|
20 | FILE *f = fopen(path, mode); |
---|
21 | #endif |
---|
22 | #endif |
---|
23 | //printFM("%p",f); |
---|
24 | if (f) return new StdioFILE(f, path); else return NULL; |
---|
25 | } |
---|
26 | |
---|
27 | VirtDIR* StdioFileSystem::Vopendir(const char* path) |
---|
28 | { |
---|
29 | //printFM("Vopendir %s",path); |
---|
30 | #ifdef _WIN32 |
---|
31 | DIRTYPE *d = wopendir(Convert::utf8ToUtf16(path).c_str()); |
---|
32 | #else |
---|
33 | DIR *d = opendir(path); |
---|
34 | #endif |
---|
35 | //printFM("%p",d); |
---|
36 | if (d) return new StdioDIR(d); else return NULL; |
---|
37 | } |
---|
38 | |
---|
39 | bool StdioFileSystem::Vfexists(const char* path) |
---|
40 | { |
---|
41 | return fileExists(path); |
---|
42 | } |
---|
43 | |
---|
44 | void StdioFILE::setStdio() |
---|
45 | { |
---|
46 | #ifndef NO_STD_IN_OUT_ERR |
---|
47 | static StdioFILEDontClose si(stdin); |
---|
48 | static StdioFILEDontClose so(stdout); |
---|
49 | static StdioFILEDontClose se(stderr); |
---|
50 | setVstdin(&si); |
---|
51 | setVstdout(&so); |
---|
52 | setVstderr(&se); |
---|
53 | #endif |
---|
54 | } |
---|
55 | |
---|
56 | dirent* StdioDIR::Vreaddir() |
---|
57 | { |
---|
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 |
---|
65 | return readdir(dir); |
---|
66 | #endif |
---|
67 | } |
---|