source: cpp/frams/virtfile/stdiofile.cpp @ 284

Last change on this file since 284 was 281, checked in by Maciej Komosinski, 10 years ago

Support for wide char (unicode) names of files and directories under Windows, internally encoded as char* utf-8

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
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
11VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode)
12{
13        //printFM("Vfopen %s %s",path,mode);
14#ifdef USE_MFILE
15        MFILE *f = mfopen(path, mode);
16#else
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
22#endif
23        //printFM("%p",f);
24        if (f) return new StdioFILE(f, path); else return 0;
25}
26
27VirtDIR* 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 0;
37}
38
39int StdioFileSystem::Vfexists(const char* path)
40{
41        return fileExists(path);
42}
43
44void 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
56dirent* 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}
Note: See TracBrowser for help on using the repository browser.