source: trunk/src/io/c_file_system.cc @ 438

Last change on this file since 438 was 438, checked in by epyon, 10 years ago
  • massive amount of std::string removal
  • removed slurp, use filesystem::slurp instead
  • lua_values const_string support
  • several bugfixes
  • program_manager and shader loading without std::string/std::stream
File size: 1.2 KB
RevLine 
[395]1// Copyright (C) 2012-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
[124]6
7#include "nv/io/c_file_system.hh"
8#include "nv/io/c_stream.hh"
[395]9#include <cstdio>
[124]10
11using namespace nv;
12
[438]13
[124]14c_file_system::c_file_system()
15{
16
17}
18
19c_file_system::~c_file_system()
20{
21
22}
23
[438]24bool c_file_system::exists( const string_view& fpath )
[124]25{
[438]26        FILE* file = ::fopen( fpath.data(), "rb" );
[124]27        if ( !file )
28        {
29                return false;
30        }
31        ::fclose( file );
32        return true;
33}
34
[438]35stream* c_file_system::open( const string_view& fpath, const string_view& fmode /*= "rb" */ )
[124]36{
[438]37        NV_ASSERT( !fpath.empty() && !fmode.empty(), "Bad parameters passed to open" );
38        FILE* file = ::fopen( fpath.data(), fmode.data() );
[124]39        if ( !file )
40        {
41                return nullptr;
42        }
[438]43        return new c_stream( file, fpath.data() );
[124]44}
[438]45
46nv::const_string c_file_system::slurp( const string_view& path )
47{
48        stream* fstream = open( path, "rb" );
49        if ( !fstream ) return const_string();
50        uint32 size = fstream->size();
51        const_string result( nullptr, size );
52        fstream->read( const_cast<char*>( result.data() ), size, 1 );
53        delete fstream;
54        return result;
55}
Note: See TracBrowser for help on using the repository browser.