2017-01-22 13:58:20 +01:00
|
|
|
/* Copyright (C) 2010-2017 The RetroArch team
|
2015-09-17 11:41:48 +02:00
|
|
|
*
|
|
|
|
* ---------------------------------------------------------------------------------------
|
2016-03-20 16:29:14 +01:00
|
|
|
* The following license statement only applies to this file (file_stream.h).
|
2015-09-17 11:41:48 +02:00
|
|
|
* ---------------------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-03-20 16:29:14 +01:00
|
|
|
#ifndef __LIBRETRO_SDK_FILE_STREAM_H
|
|
|
|
#define __LIBRETRO_SDK_FILE_STREAM_H
|
2015-09-17 11:41:48 +02:00
|
|
|
|
2017-10-29 12:08:20 -04:00
|
|
|
#include <stdio.h>
|
2015-09-17 11:41:48 +02:00
|
|
|
#include <stdint.h>
|
2017-12-10 22:35:08 +01:00
|
|
|
#include <stdlib.h>
|
2015-09-17 11:41:48 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2017-06-24 23:15:16 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2017-12-11 21:24:14 +01:00
|
|
|
#include <libretro_vfs.h>
|
2016-04-23 10:40:46 +02:00
|
|
|
#include <retro_common_api.h>
|
2017-12-10 22:35:08 +01:00
|
|
|
#include <retro_inline.h>
|
2015-09-17 20:24:49 +02:00
|
|
|
#include <boolean.h>
|
|
|
|
|
2017-09-06 23:17:00 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2017-12-14 14:03:42 +01:00
|
|
|
#define FILESTREAM_REQUIRED_VFS_VERSION 1
|
|
|
|
|
2016-04-23 10:40:46 +02:00
|
|
|
RETRO_BEGIN_DECLS
|
2015-09-17 11:41:48 +02:00
|
|
|
|
2015-09-17 19:57:51 +02:00
|
|
|
typedef struct RFILE RFILE;
|
2015-09-17 11:41:48 +02:00
|
|
|
|
2017-12-11 12:15:00 +01:00
|
|
|
#define FILESTREAM_REQUIRED_VFS_VERSION 1
|
|
|
|
|
2017-09-05 16:39:12 -04:00
|
|
|
int64_t filestream_get_size(RFILE *stream);
|
2017-02-18 02:21:33 +01:00
|
|
|
|
2017-11-17 16:12:36 -05:00
|
|
|
/**
|
|
|
|
* filestream_open:
|
|
|
|
* @path : path to file
|
|
|
|
* @mode : file mode to use when opening (read/write)
|
|
|
|
* @bufsize : optional buffer size (-1 or 0 to use default)
|
|
|
|
*
|
|
|
|
* Opens a file for reading or writing, depending on the requested mode.
|
|
|
|
* Returns a pointer to an RFILE if opened successfully, otherwise NULL.
|
|
|
|
**/
|
2017-12-10 22:25:38 +01:00
|
|
|
RFILE *filestream_open(const char *path, unsigned mode, unsigned hints);
|
2015-09-17 11:41:48 +02:00
|
|
|
|
2016-03-24 04:23:17 +01:00
|
|
|
ssize_t filestream_seek(RFILE *stream, ssize_t offset, int whence);
|
2015-09-17 11:41:48 +02:00
|
|
|
|
2016-03-24 04:23:17 +01:00
|
|
|
ssize_t filestream_read(RFILE *stream, void *data, size_t len);
|
2015-09-17 11:41:48 +02:00
|
|
|
|
2016-03-24 04:23:17 +01:00
|
|
|
ssize_t filestream_write(RFILE *stream, const void *data, size_t len);
|
2015-09-17 19:57:51 +02:00
|
|
|
|
2016-03-24 04:23:17 +01:00
|
|
|
ssize_t filestream_tell(RFILE *stream);
|
2015-09-18 05:22:50 +02:00
|
|
|
|
2016-03-24 04:23:17 +01:00
|
|
|
void filestream_rewind(RFILE *stream);
|
2015-09-18 05:22:50 +02:00
|
|
|
|
2016-03-24 04:23:17 +01:00
|
|
|
int filestream_close(RFILE *stream);
|
2015-09-17 11:41:48 +02:00
|
|
|
|
2016-03-24 04:09:25 +01:00
|
|
|
int filestream_read_file(const char *path, void **buf, ssize_t *len);
|
2015-09-19 00:19:51 +02:00
|
|
|
|
2016-06-03 00:03:58 +02:00
|
|
|
char *filestream_gets(RFILE *stream, char *s, size_t len);
|
|
|
|
|
2016-06-03 00:07:00 +02:00
|
|
|
int filestream_getc(RFILE *stream);
|
|
|
|
|
2016-06-03 07:29:27 +02:00
|
|
|
int filestream_eof(RFILE *stream);
|
|
|
|
|
2016-03-24 04:09:25 +01:00
|
|
|
bool filestream_write_file(const char *path, const void *data, ssize_t size);
|
2015-09-19 00:34:24 +02:00
|
|
|
|
2016-04-07 03:23:01 +02:00
|
|
|
int filestream_putc(RFILE *stream, int c);
|
|
|
|
|
2017-09-06 23:17:00 +02:00
|
|
|
int filestream_vprintf(RFILE *stream, const char* format, va_list args);
|
|
|
|
|
|
|
|
int filestream_printf(RFILE *stream, const char* format, ...);
|
|
|
|
|
|
|
|
int filestream_error(RFILE *stream);
|
|
|
|
|
2017-02-17 03:03:18 +01:00
|
|
|
int filestream_flush(RFILE *stream);
|
|
|
|
|
2017-12-14 00:16:18 +01:00
|
|
|
int filestream_delete(const char *path);
|
|
|
|
|
|
|
|
const char *filestream_get_path(RFILE *stream);
|
|
|
|
|
2017-12-10 22:35:08 +01:00
|
|
|
static INLINE char *filestream_getline(RFILE *stream)
|
|
|
|
{
|
|
|
|
char* newline = (char*)malloc(9);
|
|
|
|
char* newline_tmp = NULL;
|
|
|
|
size_t cur_size = 8;
|
|
|
|
size_t idx = 0;
|
|
|
|
int in = filestream_getc(stream);
|
|
|
|
|
|
|
|
if (!newline)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while (in != EOF && in != '\n')
|
|
|
|
{
|
|
|
|
if (idx == cur_size)
|
|
|
|
{
|
|
|
|
cur_size *= 2;
|
|
|
|
newline_tmp = (char*)realloc(newline, cur_size + 1);
|
|
|
|
|
|
|
|
if (!newline_tmp)
|
|
|
|
{
|
|
|
|
free(newline);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
newline = newline_tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
newline[idx++] = in;
|
|
|
|
in = filestream_getc(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
newline[idx] = '\0';
|
|
|
|
return newline;
|
|
|
|
}
|
|
|
|
|
2016-04-23 10:40:46 +02:00
|
|
|
RETRO_END_DECLS
|
2015-09-17 11:41:48 +02:00
|
|
|
|
|
|
|
#endif
|