source: cpp/common/virtfile/stdiofile.cpp @ 753

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

The NO_STD_IN_OUT_ERR macro excludes entire functions, not their contents

  • Property svn:eol-style set to native
File size: 1.9 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/log.h>
9#include <common/Convert.h>
10#ifdef __ANDROID__
11#include <common/dirs.h>
12#include <common/platform/android/AndroidAPK_DIR.h>
13#endif
14
15VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode)
16{
17        //log_printf("Vfopen %s %s",path,mode);
18#if defined USE_MFILE || defined _WIN32
19        MFILE *f = mfopen(path, mode);
20#else
21        FILE *f = fopen(path, mode);
22#endif
23        //log_printf("%p",f);
24        if (f) return new StdioFILE(f, path); else return NULL;
25}
26
27VirtDIR* StdioFileSystem::Vopendir(const char* path)
28{
29        //log_printf("Vopendir %s",path);
30#ifdef __ANDROID__
31        int resources_prefix_length=getAppResourcesDir().length();
32        if (strncmp(path, getAppResourcesDir().c_str(), resources_prefix_length) == 0) //it is a resources dir
33        {
34                VirtDIR *vd = AndroidAPK_DIR::opendir(path+resources_prefix_length+1); //+1 because we also skip '/' and start with a "relative" dir, otherwise it does not work.
35                return vd;
36        }
37#endif
38
39#ifdef _WIN32
40        DIRTYPE *d = wopendir(Convert::utf8ToUtf16(path).c_str());
41#else
42        DIR *d = opendir(path);
43#endif
44        //log_printf("%p",d);
45        if (d) return new StdioDIR(d); else return NULL;
46}
47
48bool StdioFileSystem::Vfexists(const char* path)
49{
50        return fileExists(path);
51}
52
53#ifndef NO_STD_IN_OUT_ERR
54void StdioFILE::setStdio()
55{
56        static StdioFILEDontClose si(stdin);
57        static StdioFILEDontClose so(stdout);
58        static StdioFILEDontClose se(stderr);
59        setVstdin(&si);
60        setVstdout(&so);
61        setVstderr(&se);
62}
63#endif
64
65dirent* StdioDIR::Vreaddir()
66{
67        //log_printf("Vreaddir %s",dir);
68#ifdef _WIN32
69        wdirent *wde=wreaddir(dir);
70        if (wde==NULL) return NULL;
71        strcpy(de.d_name, Convert::wstrToUtf8(wde->d_name).c_str());
72        return &de;
73#else
74        return readdir(dir);
75#endif
76}
Note: See TracBrowser for help on using the repository browser.