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 #include <libretro.h>
23 
24 #include "Stream.h"
25 #include "FileStream.h"
26 
FileStream(const char * path,const int mode)27 FileStream::FileStream(const char *path, const int mode)
28 {
29    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);
30 }
31 
~FileStream()32 FileStream::~FileStream()
33 {
34    if (fp)
35    {
36       filestream_close(fp);
37       fp = NULL;
38    }
39 }
40 
read(void * data,uint64_t count)41 uint64_t FileStream::read(void *data, uint64_t count)
42 {
43    if (!fp)
44       return 0;
45    return filestream_read(fp, data, count);
46 }
47 
write(const void * data,uint64_t count)48 void FileStream::write(const void *data, uint64_t count)
49 {
50    if (!fp)
51       return;
52    filestream_write(fp, data, count);
53 }
54 
seek(int64_t offset,int whence)55 void FileStream::seek(int64_t offset, int whence)
56 {
57    int seek_position = -1;
58    if (!fp)
59       return;
60    switch (whence)
61    {
62       case SEEK_SET:
63          seek_position = RETRO_VFS_SEEK_POSITION_START;
64          break;
65       case SEEK_CUR:
66          seek_position = RETRO_VFS_SEEK_POSITION_CURRENT;
67          break;
68       case SEEK_END:
69          seek_position = RETRO_VFS_SEEK_POSITION_END;
70          break;
71    }
72    filestream_seek(fp, offset, seek_position);
73 }
74 
tell(void)75 uint64_t FileStream::tell(void)
76 {
77    if (!fp)
78       return -1;
79    return filestream_tell(fp);
80 }
81 
size(void)82 uint64_t FileStream::size(void)
83 {
84    if (!fp)
85       return -1;
86    return filestream_get_size(fp);
87 }
88 
truncate(uint64_t length)89 void FileStream::truncate(uint64_t length)
90 {
91 }
92 
flush(void)93 void FileStream::flush(void)
94 {
95 }
96 
close(void)97 void FileStream::close(void)
98 {
99    if (!fp)
100       return;
101    filestream_close(fp);
102    fp = NULL;
103 }
104