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

Last change on this file since 281 was 281, checked in by Maciej Komosinski, 11 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
RevLine 
[121]1// This file is a part of the Framsticks GDK.
[197]2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
[109]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>
[281]9#include <common/Convert.h>
[109]10
[281]11VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode)
[109]12{
13        //printFM("Vfopen %s %s",path,mode);
[206]14#ifdef USE_MFILE
[281]15        MFILE *f = mfopen(path, mode);
[206]16#else
[281]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);
[206]21#endif
[281]22#endif
[109]23        //printFM("%p",f);
[281]24        if (f) return new StdioFILE(f, path); else return 0;
[109]25}
26
27VirtDIR* StdioFileSystem::Vopendir(const char* path)
28{
29        //printFM("Vopendir %s",path);
[281]30#ifdef _WIN32
31        DIRTYPE *d = wopendir(Convert::utf8ToUtf16(path).c_str());
32#else
33        DIR *d = opendir(path);
34#endif
[109]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{
[227]46#ifndef NO_STD_IN_OUT_ERR
[109]47        static StdioFILEDontClose si(stdin);
48        static StdioFILEDontClose so(stdout);
49        static StdioFILEDontClose se(stderr);
50        setVstdin(&si);
51        setVstdout(&so);
52        setVstderr(&se);
[227]53#endif
[109]54}
55
56dirent* StdioDIR::Vreaddir()
57{
58        //printFM("Vreaddir %s",dir);
[281]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
[109]65        return readdir(dir);
[281]66#endif
[109]67}
Note: See TracBrowser for help on using the repository browser.