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