Start adding streams/interface_stream.c

This commit is contained in:
twinaphex 2016-04-06 21:58:23 +02:00
parent 7fe34b97a6
commit 5eb3bb05f7
4 changed files with 132 additions and 0 deletions

View File

@ -133,6 +133,8 @@ OBJ += frontend/frontend.o \
libretro-common/lists/dir_list.o \
libretro-common/file/retro_dirent.o \
libretro-common/streams/file_stream.o \
libretro-common/streams/interface_stream.o \
libretro-common/streams/memory_stream.o \
libretro-common/file/retro_stat.o \
libretro-common/lists/string_list.o \
libretro-common/string/stdstring.o \

View File

@ -643,6 +643,8 @@ FILE
#include "../libretro-common/lists/file_list.c"
#include "../libretro-common/file/retro_dirent.c"
#include "../libretro-common/streams/file_stream.c"
#include "../libretro-common/streams/interface_stream.c"
#include "../libretro-common/streams/memory_stream.c"
#include "../libretro-common/file/retro_stat.c"
#include "../list_special.c"
#include "../libretro-common/string/stdstring.c"

View File

@ -0,0 +1,56 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (memory_stream.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 _LIBRETRO_SDK_INTERFACE_STREAM_H
#define _LIBRETRO_SDK_INTERFACE_STREAM_H
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
enum intfstream_type
{
INTFSTREAM_FILE = 0,
INTFSTREAM_MEMORY
};
typedef struct intfstream_internal intfstream_internal_t;
typedef struct intfstream intfstream_t;
typedef struct intfstream_info
{
struct
{
uint8_t *data;
unsigned size;
} buf;
enum intfstream_type type;
} intfstream_info_t;
void *intfstream_init(intfstream_info_t *info);
bool intfstream_resize(intfstream_internal_t *intf,
intfstream_info_t *info);
#endif

View File

@ -0,0 +1,72 @@
#include <stdlib.h>
#include <streams/interface_stream.h>
#include <streams/file_stream.h>
#include <streams/memory_stream.h>
struct intfstream_internal
{
enum intfstream_type type;
struct
{
struct
{
uint8_t *data;
unsigned size;
} buf;
} memory;
};
bool intfstream_resize(intfstream_internal_t *intf, intfstream_info_t *info)
{
if (!intf || !info)
return false;
switch (intf->type)
{
case INTFSTREAM_FILE:
break;
case INTFSTREAM_MEMORY:
intf->memory.buf.data = info->buf.data;
intf->memory.buf.size = info->buf.size;
memstream_set_buffer(intf->memory.buf.data,
intf->memory.buf.size);
break;
}
return true;
}
void *intfstream_init(intfstream_info_t *info)
{
intfstream_internal_t *intf = NULL;
if (!info)
goto error;
intf = (intfstream_internal_t*)calloc(1, sizeof(*intf));
if (!intf)
goto error;
intf->type = info->type;
switch (intf->type)
{
case INTFSTREAM_FILE:
break;
case INTFSTREAM_MEMORY:
if (!intfstream_resize(intf, info))
goto error;
break;
}
return intf;
error:
if (intf)
free(intf);
return NULL;
}