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

Last change on this file since 525 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
Line 
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.
6
7#include "nv/io/c_file_system.hh"
8#include "nv/io/c_stream.hh"
9#include <cstdio>
10
11using namespace nv;
12
13
14c_file_system::c_file_system()
15{
16
17}
18
19c_file_system::~c_file_system()
20{
21
22}
23
24bool c_file_system::exists( const string_view& fpath )
25{
26        FILE* file = ::fopen( fpath.data(), "rb" );
27        if ( !file )
28        {
29                return false;
30        }
31        ::fclose( file );
32        return true;
33}
34
35stream* c_file_system::open( const string_view& fpath, const string_view& fmode /*= "rb" */ )
36{
37        NV_ASSERT( !fpath.empty() && !fmode.empty(), "Bad parameters passed to open" );
38        FILE* file = ::fopen( fpath.data(), fmode.data() );
39        if ( !file )
40        {
41                return nullptr;
42        }
43        return new c_stream( file, fpath.data() );
44}
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.