1 // TODO/WIP
2
3 /* Mednafen - Multi-system Emulator
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include <stdarg.h>
21 #include <string.h>
22
23
24 #include "mednafen.h"
25 #include "Stream.h"
26 #include "FileStream.h"
27
FileStream(const char * path,const int mode)28 FileStream::FileStream(const char *path, const int mode)
29 {
30 fp = filestream_open(path, (mode == MODE_WRITE || mode == MODE_WRITE_INPLACE) ? RETRO_VFS_FILE_ACCESS_WRITE : RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
31
32 if (!fp)
33 {
34 ErrnoHolder ene(errno);
35
36 MDFN_Error(ene.Errno(), "Error opening file:\n%s\n%s", path, ene.StrError());
37 }
38 }
39
~FileStream()40 FileStream::~FileStream()
41 {
42 }
43
read(void * data,uint64_t count,bool error_on_eos)44 uint64_t FileStream::read(void *data, uint64_t count, bool error_on_eos)
45 {
46 if (!fp)
47 return 0;
48 return filestream_read(fp, data, count);
49 }
50
write(const void * data,uint64_t count)51 void FileStream::write(const void *data, uint64_t count)
52 {
53 if (!fp)
54 return;
55 filestream_write(fp, data, count);
56 }
57
seek(int64_t offset,int whence)58 void FileStream::seek(int64_t offset, int whence)
59 {
60 if (!fp)
61 return;
62 filestream_seek(fp, offset, whence);
63 }
64
tell(void)65 uint64_t FileStream::tell(void)
66 {
67 if (!fp)
68 return -1;
69 return filestream_tell(fp);
70 }
71
size(void)72 uint64_t FileStream::size(void)
73 {
74 if (!fp)
75 return -1;
76 return filestream_get_size(fp);
77 }
78
truncate(uint64_t length)79 void FileStream::truncate(uint64_t length)
80 {
81 }
82
flush(void)83 void FileStream::flush(void)
84 {
85 }
86
close(void)87 void FileStream::close(void)
88 {
89 if (!fp)
90 return;
91 filestream_close(fp);
92 }
93