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

Last change on this file since 374 was 374, checked in by Maciej Komosinski, 9 years ago

Under _WIN32, mfopen() now redirects to a function mfile_wfopen() that converts arguments to wide char and then uses _wfopen()

  • Property svn:eol-style set to native
File size: 1.4 KB
RevLine 
[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]11VirtFILE* 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
23VirtDIR* 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]35bool StdioFileSystem::Vfexists(const char* path)
[109]36{
37        return fileExists(path);
38}
39
40void 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
52dirent* 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}
Note: See TracBrowser for help on using the repository browser.