mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
(libretro-common) Start adding retro_file.c and retro_file.h
This commit is contained in:
parent
8ced8b00e4
commit
da3bec58b1
@ -131,6 +131,7 @@ OBJ += frontend/frontend.o \
|
||||
libretro-common/file/file_list.o \
|
||||
libretro-common/file/dir_list.o \
|
||||
libretro-common/file/retro_dirent.o \
|
||||
libretro-common/file/retro_file.o \
|
||||
libretro-common/string/string_list.o \
|
||||
libretro-common/string/stdstring.o \
|
||||
libretro-common/memmap/memalign.o \
|
||||
|
@ -578,6 +578,7 @@ FILE
|
||||
#include "../libretro-common/file/dir_list.c"
|
||||
#endif
|
||||
#include "../libretro-common/file/retro_dirent.c"
|
||||
#include "../libretro-common/file/retro_file.c"
|
||||
#include "../dir_list_special.c"
|
||||
#include "../libretro-common/string/string_list.c"
|
||||
#include "../libretro-common/string/stdstring.c"
|
||||
|
109
libretro-common/file/retro_file.c
Normal file
109
libretro-common/file/retro_file.c
Normal file
@ -0,0 +1,109 @@
|
||||
#include <retro_file.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <compat/posix_string.h>
|
||||
# ifdef _MSC_VER
|
||||
# define setmode _setmode
|
||||
# endif
|
||||
# ifdef _XBOX
|
||||
# include <xtl.h>
|
||||
# define INVALID_FILE_ATTRIBUTES -1
|
||||
# else
|
||||
# include <io.h>
|
||||
# include <fcntl.h>
|
||||
# include <direct.h>
|
||||
# include <windows.h>
|
||||
# endif
|
||||
#elif defined(VITA)
|
||||
# include <psp2/io/fcntl.h>
|
||||
# include <psp2/io/dirent.h>
|
||||
#else
|
||||
# if defined(PSP)
|
||||
# include <pspiofilemgr.h>
|
||||
# endif
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <dirent.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
#include <cell/cell_fs.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
struct RFILE
|
||||
{
|
||||
int fd;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MODE_READ = 0,
|
||||
MODE_WRITE,
|
||||
MODE_READ_WRITE,
|
||||
};
|
||||
|
||||
struct RFILE *retro_fopen(const char *path, const char *mode, size_t len)
|
||||
{
|
||||
int flags = 0;
|
||||
struct RFILE *stream = (struct RFILE*)calloc(1, sizeof(*stream));
|
||||
|
||||
if (!stream)
|
||||
return NULL;
|
||||
|
||||
if (!strcmp(mode, "w+"))
|
||||
flags = MODE_READ_WRITE;
|
||||
|
||||
switch (flags)
|
||||
{
|
||||
case MODE_READ:
|
||||
break;
|
||||
case MODE_WRITE:
|
||||
break;
|
||||
case MODE_READ_WRITE:
|
||||
#ifdef _WIN32
|
||||
stream->fd = open(path, O_RDWR | O_BINARY);
|
||||
#else
|
||||
stream->fd = open(path, O_RDWR);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
ssize_t retro_seek(struct RFILE *stream, ssize_t offset, int whence)
|
||||
{
|
||||
if (!stream)
|
||||
return -1;
|
||||
|
||||
return lseek(stream->fd, offset, whence);
|
||||
}
|
||||
|
||||
ssize_t retro_read(struct RFILE *stream, void *s, size_t len)
|
||||
{
|
||||
if (!stream)
|
||||
return -1;
|
||||
return read(stream->fd, s, len);
|
||||
}
|
||||
|
||||
ssize_t retro_write(struct RFILE *stream, const void *s, size_t len)
|
||||
{
|
||||
if (!stream)
|
||||
return -1;
|
||||
return write(stream->fd, s, len);
|
||||
}
|
||||
|
||||
void retro_fclose(struct RFILE *stream)
|
||||
{
|
||||
if (!stream)
|
||||
return;
|
||||
|
||||
free(stream);
|
||||
}
|
51
libretro-common/include/retro_file.h
Normal file
51
libretro-common/include/retro_file.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 2010-2015 The RetroArch team
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
* The following license statement only applies to this file (retro_file.h).
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge,
|
||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __RETRO_FILE_H
|
||||
#define __RETRO_FILE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct RFILE;
|
||||
|
||||
struct RFILE *retro_fopen(const char *path, const char *mode, size_t len);
|
||||
|
||||
ssize_t retro_seek(struct RFILE *stream, ssize_t offset, int whence);
|
||||
|
||||
ssize_t retro_read(struct RFILE *stream, void *s, size_t len);
|
||||
|
||||
ssize_t retro_write(struct RFILE *stream, const void *s, size_t len);
|
||||
|
||||
void retro_fclose(struct RFILE *stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user