Mercurial > audlegacy
comparison Plugins/Input/console/Vfs_File.cpp @ 493:c04dff121e1d trunk
[svn] hostile merge, phase 2: reimport based on new plugin code
author | nenolod |
---|---|
date | Tue, 24 Jan 2006 20:19:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
492:ccb68bad47b2 | 493:c04dff121e1d |
---|---|
1 | |
2 #include "Vfs_File.h" | |
3 | |
4 #include "libaudacious/vfs.h" | |
5 | |
6 Vfs_File_Reader::Vfs_File_Reader() : file_( NULL ) { } | |
7 | |
8 Vfs_File_Reader::~Vfs_File_Reader() { close(); } | |
9 | |
10 Vfs_File_Reader::error_t Vfs_File_Reader::open( const char* path ) | |
11 { | |
12 file_ = vfs_fopen( path, "rb" ); | |
13 if ( !file_ ) | |
14 return "Couldn't open file"; | |
15 return 0; | |
16 } | |
17 | |
18 long Vfs_File_Reader::size() const | |
19 { | |
20 long pos = tell(); | |
21 vfs_fseek( (VFSFile*) file_, 0, SEEK_END ); | |
22 long result = tell(); | |
23 vfs_fseek( (VFSFile*) file_, pos, SEEK_SET ); | |
24 return result; | |
25 } | |
26 | |
27 long Vfs_File_Reader::read_avail( void* p, long s ) | |
28 { | |
29 return (long) vfs_fread( p, 1, s, (VFSFile*) file_ ); | |
30 } | |
31 | |
32 long Vfs_File_Reader::tell() const | |
33 { | |
34 return vfs_ftell( (VFSFile*) file_ ); | |
35 } | |
36 | |
37 Vfs_File_Reader::error_t Vfs_File_Reader::seek( long n ) | |
38 { | |
39 if ( n == 0 ) // optimization | |
40 vfs_rewind( (VFSFile*) file_ ); | |
41 else if ( vfs_fseek( (VFSFile*) file_, n, SEEK_SET ) != 0 ) | |
42 return "Error seeking in file"; | |
43 return 0; | |
44 } | |
45 | |
46 void Vfs_File_Reader::close() | |
47 { | |
48 if ( file_ ) | |
49 { | |
50 vfs_fclose( (VFSFile*) file_ ); | |
51 file_ = 0; | |
52 } | |
53 } | |
54 |