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
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>
[375]8#include <common/log.h>
[281]9#include <common/Convert.h>
[425]10#ifdef __ANDROID__
11#include <common/dirs.h>
12#include <common/platform/android/AndroidAPK_DIR.h>
13#endif
[109]14
[281]15VirtFILE* StdioFileSystem::Vfopen(const char *path, const char *mode)
[109]16{
[375]17        //log_printf("Vfopen %s %s",path,mode);
[374]18#if defined USE_MFILE || defined _WIN32
[281]19        MFILE *f = mfopen(path, mode);
[206]20#else
[281]21        FILE *f = fopen(path, mode);
[206]22#endif
[375]23        //log_printf("%p",f);
[298]24        if (f) return new StdioFILE(f, path); else return NULL;
[109]25}
26
27VirtDIR* StdioFileSystem::Vopendir(const char* path)
28{
[375]29        //log_printf("Vopendir %s",path);
[425]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
[281]39#ifdef _WIN32
40        DIRTYPE *d = wopendir(Convert::utf8ToUtf16(path).c_str());
41#else
42        DIR *d = opendir(path);
43#endif
[375]44        //log_printf("%p",d);
[298]45        if (d) return new StdioDIR(d); else return NULL;
[109]46}
47
[295]48bool StdioFileSystem::Vfexists(const char* path)
[109]49{
50        return fileExists(path);
51}
52
[425]53#ifndef NO_STD_IN_OUT_ERR
[109]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);
[425]62}
[227]63#endif
[109]64
65dirent* StdioDIR::Vreaddir()
66{
[375]67        //log_printf("Vreaddir %s",dir);
[281]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
[109]74        return readdir(dir);
[281]75#endif
[109]76}
Note: See TracBrowser for help on using the repository browser.