2012-10-13 13:31:49 +00:00
|
|
|
// TODO/WIP
|
|
|
|
|
|
|
|
/* Mednafen - Multi-system Emulator
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2015-10-01 01:11:33 +00:00
|
|
|
|
2012-10-13 13:31:49 +00:00
|
|
|
#include "mednafen.h"
|
|
|
|
#include "Stream.h"
|
|
|
|
#include "FileStream.h"
|
|
|
|
|
2012-11-16 15:33:10 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2012-10-13 13:31:49 +00:00
|
|
|
|
2016-08-14 09:54:31 +00:00
|
|
|
FileStream::FileStream(const char *path, const int mode)
|
2012-10-13 13:31:49 +00:00
|
|
|
{
|
2017-12-16 02:07:16 +00:00
|
|
|
fp = filestream_open(path, (mode == MODE_WRITE) ? RETRO_VFS_FILE_ACCESS_WRITE : RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
2012-10-13 13:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileStream::~FileStream()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-01 01:11:33 +00:00
|
|
|
uint64_t FileStream::read(void *data, uint64_t count, bool error_on_eos)
|
2012-10-13 13:31:49 +00:00
|
|
|
{
|
2015-10-01 01:11:33 +00:00
|
|
|
if (!fp)
|
|
|
|
return 0;
|
2016-03-24 05:33:52 +00:00
|
|
|
return filestream_read(fp, data, count);
|
2012-10-13 13:31:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 01:11:33 +00:00
|
|
|
void FileStream::write(const void *data, uint64_t count)
|
2012-10-13 13:31:49 +00:00
|
|
|
{
|
2015-10-01 01:11:33 +00:00
|
|
|
if (!fp)
|
|
|
|
return;
|
2016-03-24 05:33:52 +00:00
|
|
|
filestream_write(fp, data, count);
|
2012-10-13 13:31:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 01:11:33 +00:00
|
|
|
void FileStream::seek(int64_t offset, int whence)
|
2012-10-13 13:31:49 +00:00
|
|
|
{
|
2015-10-01 01:11:33 +00:00
|
|
|
if (!fp)
|
|
|
|
return;
|
2016-03-24 05:33:52 +00:00
|
|
|
filestream_seek(fp, offset, whence);
|
2012-10-13 13:31:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 01:11:33 +00:00
|
|
|
int64_t FileStream::tell(void)
|
2012-10-13 13:31:49 +00:00
|
|
|
{
|
2015-10-01 01:11:33 +00:00
|
|
|
if (!fp)
|
|
|
|
return -1;
|
2016-03-24 05:33:52 +00:00
|
|
|
return filestream_tell(fp);
|
2012-10-13 13:31:49 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 01:11:33 +00:00
|
|
|
int64_t FileStream::size(void)
|
2012-10-13 13:31:49 +00:00
|
|
|
{
|
2017-12-18 12:26:30 +00:00
|
|
|
if (!fp)
|
2015-10-01 01:11:33 +00:00
|
|
|
return -1;
|
2017-12-18 12:26:30 +00:00
|
|
|
return filestream_get_size(fp);
|
2012-10-13 13:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileStream::close(void)
|
|
|
|
{
|
2015-10-01 01:11:33 +00:00
|
|
|
if (!fp)
|
2014-04-20 16:49:46 +00:00
|
|
|
return;
|
2016-03-24 05:33:52 +00:00
|
|
|
filestream_close(fp);
|
2012-10-13 13:31:49 +00:00
|
|
|
}
|