beetle-pce-fast-libretro/mednafen/FileStream.cpp

82 lines
1.8 KiB
C++
Raw Normal View History

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
*/
2020-10-05 21:30:44 +00:00
#include <stdarg.h>
#include <string.h>
2012-10-13 13:31:49 +00:00
#include "Stream.h"
#include "FileStream.h"
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()
{
if (fp)
{
filestream_close(fp);
fp = NULL;
}
2012-10-13 13:31:49 +00:00
}
2021-04-08 18:40:48 +00:00
uint64_t FileStream::read(void *data, uint64_t count)
2012-10-13 13:31:49 +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
}
void FileStream::write(const void *data, uint64_t count)
2012-10-13 13:31:49 +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
}
void FileStream::seek(int64_t offset, int whence)
2012-10-13 13:31:49 +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
}
int64_t FileStream::tell(void)
2012-10-13 13:31:49 +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
}
int64_t FileStream::size(void)
2012-10-13 13:31:49 +00:00
{
2017-12-18 12:26:30 +00:00
if (!fp)
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)
{
if (!fp)
2014-04-20 16:49:46 +00:00
return;
2016-03-24 05:33:52 +00:00
filestream_close(fp);
fp = NULL;
2012-10-13 13:31:49 +00:00
}