Last change
on this file since 534 was
534,
checked in by epyon, 8 years ago
|
CONTINUED:
- getting rid of size_t
- datatypes now restricted to uint32 size
- 64-bit compatibility
- copyright updates where modified
|
File size:
1.2 KB
|
Rev | Line | |
---|
[534] | 1 | // Copyright (C) 2012-2017 ChaosForge Ltd
|
---|
[395] | 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 |
|
---|
| 11 | using namespace nv;
|
---|
| 12 |
|
---|
[438] | 13 |
|
---|
[124] | 14 | c_file_system::c_file_system()
|
---|
| 15 | {
|
---|
| 16 |
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | c_file_system::~c_file_system()
|
---|
| 20 | {
|
---|
| 21 |
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[438] | 24 | bool 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] | 35 | stream* 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 |
|
---|
| 46 | nv::const_string c_file_system::slurp( const string_view& path )
|
---|
| 47 | {
|
---|
| 48 | stream* fstream = open( path, "rb" );
|
---|
| 49 | if ( !fstream ) return const_string();
|
---|
[533] | 50 | uint32 size = static_cast< uint32 >( fstream->size() );
|
---|
[438] | 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.