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

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

0 -> NULL or false

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
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
11VirtFILE* 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
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 NULL;
37}
38
39bool 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.