Mercurial > audlegacy
comparison Plugins/Input/console/abstract_file.cpp @ 479:0b9507985f0d trunk
[svn] Use the VFS subsystem and delete the unused demo source.
| author | chainsaw |
|---|---|
| date | Sat, 21 Jan 2006 06:32:50 -0800 |
| parents | 252843aac42f |
| children | 7c5e886205ef |
comparison
equal
deleted
inserted
replaced
| 478:5064517c685c | 479:0b9507985f0d |
|---|---|
| 135 close(); | 135 close(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 error_t Std_File_Reader::open( const char* path ) | 138 error_t Std_File_Reader::open( const char* path ) |
| 139 { | 139 { |
| 140 file = fopen( path, "rb" ); | 140 file = vfs_fopen( path, "rb" ); |
| 141 if ( !file ) | 141 if ( !file ) |
| 142 RAISE_ERROR( "Couldn't open file" ); | 142 RAISE_ERROR( "Couldn't open file" ); |
| 143 return NULL; | 143 return NULL; |
| 144 } | 144 } |
| 145 | 145 |
| 146 long Std_File_Reader::size() const | 146 long Std_File_Reader::size() const |
| 147 { | 147 { |
| 148 long pos = tell(); | 148 long pos = tell(); |
| 149 fseek( file, 0, SEEK_END ); | 149 vfs_fseek( file, 0, SEEK_END ); |
| 150 long result = tell(); | 150 long result = tell(); |
| 151 fseek( file, pos, SEEK_SET ); | 151 vfs_fseek( file, pos, SEEK_SET ); |
| 152 return result; | 152 return result; |
| 153 } | 153 } |
| 154 | 154 |
| 155 long Std_File_Reader::read_avail( void* p, long s ) { | 155 long Std_File_Reader::read_avail( void* p, long s ) { |
| 156 return fread( p, 1, s, file ); | 156 return vfs_fread( p, 1, s, file ); |
| 157 } | 157 } |
| 158 | 158 |
| 159 long Std_File_Reader::tell() const { | 159 long Std_File_Reader::tell() const { |
| 160 return ftell( file ); | 160 return vfs_ftell( file ); |
| 161 } | 161 } |
| 162 | 162 |
| 163 error_t Std_File_Reader::seek( long n ) | 163 error_t Std_File_Reader::seek( long n ) |
| 164 { | 164 { |
| 165 if ( fseek( file, n, SEEK_SET ) != 0 ) | 165 if ( vfs_fseek( file, n, SEEK_SET ) != 0 ) |
| 166 RAISE_ERROR( "Error seeking in file" ); | 166 RAISE_ERROR( "Error seeking in file" ); |
| 167 return NULL; | 167 return NULL; |
| 168 } | 168 } |
| 169 | 169 |
| 170 void Std_File_Reader::close() | 170 void Std_File_Reader::close() |
| 171 { | 171 { |
| 172 if ( file ) { | 172 if ( file ) { |
| 173 fclose( file ); | 173 vfs_fclose( file ); |
| 174 file = NULL; | 174 file = NULL; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Std_File_Writer | 178 // Std_File_Writer |
| 184 close(); | 184 close(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 error_t Std_File_Writer::open( const char* path ) | 187 error_t Std_File_Writer::open( const char* path ) |
| 188 { | 188 { |
| 189 file = fopen( path, "wb" ); | 189 file = vfs_fopen( path, "wb" ); |
| 190 if ( !file ) | 190 if ( !file ) |
| 191 RAISE_ERROR( "Couldn't open file for writing" ); | 191 RAISE_ERROR( "Couldn't open file for writing" ); |
| 192 | 192 |
| 193 // to do: increase file buffer size | 193 // to do: increase file buffer size |
| 194 //setvbuf( file, NULL, _IOFBF, 32 * 1024L ); | 194 //setvbuf( file, NULL, _IOFBF, 32 * 1024L ); |
| 196 return NULL; | 196 return NULL; |
| 197 } | 197 } |
| 198 | 198 |
| 199 error_t Std_File_Writer::write( const void* p, long s ) | 199 error_t Std_File_Writer::write( const void* p, long s ) |
| 200 { | 200 { |
| 201 long result = fwrite( p, 1, s, file ); | 201 long result = vfs_fwrite( p, 1, s, file ); |
| 202 if ( result != s ) | 202 if ( result != s ) |
| 203 RAISE_ERROR( "Couldn't write to file" ); | 203 RAISE_ERROR( "Couldn't write to file" ); |
| 204 return NULL; | 204 return NULL; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void Std_File_Writer::close() | 207 void Std_File_Writer::close() |
| 208 { | 208 { |
| 209 if ( file ) { | 209 if ( file ) { |
| 210 fclose( file ); | 210 vfs_fclose( file ); |
| 211 file = NULL; | 211 file = NULL; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 // Mem_Writer | 215 // Mem_Writer |
