remove a bunch of eol-style properties... again.. bear with me.
This commit is contained in:
parent
7f0c1276d4
commit
a0e0aed5a4
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,213 +1,213 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (archive_file_zlib.c).
|
* The following license statement only applies to this file (archive_file_zlib.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <compat/zlib.h>
|
#include <compat/zlib.h>
|
||||||
#include <file/archive_file.h>
|
#include <file/archive_file.h>
|
||||||
#include <streams/file_stream.h>
|
#include <streams/file_stream.h>
|
||||||
|
|
||||||
static void *zlib_stream_new(void)
|
static void *zlib_stream_new(void)
|
||||||
{
|
{
|
||||||
return (z_stream*)calloc(1, sizeof(z_stream));
|
return (z_stream*)calloc(1, sizeof(z_stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zlib_stream_free(void *data)
|
static void zlib_stream_free(void *data)
|
||||||
{
|
{
|
||||||
z_stream *ret = (z_stream*)data;
|
z_stream *ret = (z_stream*)data;
|
||||||
if (ret)
|
if (ret)
|
||||||
inflateEnd(ret);
|
inflateEnd(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zlib_stream_set(void *data,
|
static void zlib_stream_set(void *data,
|
||||||
uint32_t avail_in,
|
uint32_t avail_in,
|
||||||
uint32_t avail_out,
|
uint32_t avail_out,
|
||||||
const uint8_t *next_in,
|
const uint8_t *next_in,
|
||||||
uint8_t *next_out
|
uint8_t *next_out
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
stream->avail_in = avail_in;
|
stream->avail_in = avail_in;
|
||||||
stream->avail_out = avail_out;
|
stream->avail_out = avail_out;
|
||||||
|
|
||||||
stream->next_in = (uint8_t*)next_in;
|
stream->next_in = (uint8_t*)next_in;
|
||||||
stream->next_out = next_out;
|
stream->next_out = next_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t zlib_stream_get_avail_in(void *data)
|
static uint32_t zlib_stream_get_avail_in(void *data)
|
||||||
{
|
{
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return stream->avail_in;
|
return stream->avail_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t zlib_stream_get_avail_out(void *data)
|
static uint32_t zlib_stream_get_avail_out(void *data)
|
||||||
{
|
{
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return stream->avail_out;
|
return stream->avail_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t zlib_stream_get_total_out(void *data)
|
static uint64_t zlib_stream_get_total_out(void *data)
|
||||||
{
|
{
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return stream->total_out;
|
return stream->total_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zlib_stream_decrement_total_out(void *data, unsigned subtraction)
|
static void zlib_stream_decrement_total_out(void *data, unsigned subtraction)
|
||||||
{
|
{
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (stream)
|
if (stream)
|
||||||
stream->total_out -= subtraction;
|
stream->total_out -= subtraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zlib_stream_compress_free(void *data)
|
static void zlib_stream_compress_free(void *data)
|
||||||
{
|
{
|
||||||
z_stream *ret = (z_stream*)data;
|
z_stream *ret = (z_stream*)data;
|
||||||
if (ret)
|
if (ret)
|
||||||
deflateEnd(ret);
|
deflateEnd(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int zlib_stream_compress_data_to_file(void *data)
|
static int zlib_stream_compress_data_to_file(void *data)
|
||||||
{
|
{
|
||||||
int zstatus;
|
int zstatus;
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
zstatus = deflate(stream, Z_FINISH);
|
zstatus = deflate(stream, Z_FINISH);
|
||||||
|
|
||||||
if (zstatus == Z_STREAM_END)
|
if (zstatus == Z_STREAM_END)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool zlib_stream_decompress_init(void *data)
|
static bool zlib_stream_decompress_init(void *data)
|
||||||
{
|
{
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return false;
|
return false;
|
||||||
if (inflateInit(stream) != Z_OK)
|
if (inflateInit(stream) != Z_OK)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool zlib_stream_decompress_data_to_file_init(
|
static bool zlib_stream_decompress_data_to_file_init(
|
||||||
file_archive_file_handle_t *handle,
|
file_archive_file_handle_t *handle,
|
||||||
const uint8_t *cdata, uint32_t csize, uint32_t size)
|
const uint8_t *cdata, uint32_t csize, uint32_t size)
|
||||||
{
|
{
|
||||||
if (!handle)
|
if (!handle)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(handle->stream = (z_stream*)zlib_stream_new()))
|
if (!(handle->stream = (z_stream*)zlib_stream_new()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (inflateInit2((z_streamp)handle->stream, -MAX_WBITS) != Z_OK)
|
if (inflateInit2((z_streamp)handle->stream, -MAX_WBITS) != Z_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
handle->data = (uint8_t*)malloc(size);
|
handle->data = (uint8_t*)malloc(size);
|
||||||
|
|
||||||
if (!handle->data)
|
if (!handle->data)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
zlib_stream_set(handle->stream, csize, size,
|
zlib_stream_set(handle->stream, csize, size,
|
||||||
(const uint8_t*)cdata, handle->data);
|
(const uint8_t*)cdata, handle->data);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
zlib_stream_free(handle->stream);
|
zlib_stream_free(handle->stream);
|
||||||
free(handle->stream);
|
free(handle->stream);
|
||||||
if (handle->data)
|
if (handle->data)
|
||||||
free(handle->data);
|
free(handle->data);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int zlib_stream_decompress_data_to_file_iterate(void *data)
|
static int zlib_stream_decompress_data_to_file_iterate(void *data)
|
||||||
{
|
{
|
||||||
int zstatus;
|
int zstatus;
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
zstatus = inflate(stream, Z_NO_FLUSH);
|
zstatus = inflate(stream, Z_NO_FLUSH);
|
||||||
|
|
||||||
if (zstatus == Z_STREAM_END)
|
if (zstatus == Z_STREAM_END)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (zstatus != Z_OK && zstatus != Z_BUF_ERROR)
|
if (zstatus != Z_OK && zstatus != Z_BUF_ERROR)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zlib_stream_compress_init(void *data, int level)
|
static void zlib_stream_compress_init(void *data, int level)
|
||||||
{
|
{
|
||||||
z_stream *stream = (z_stream*)data;
|
z_stream *stream = (z_stream*)data;
|
||||||
|
|
||||||
if (stream)
|
if (stream)
|
||||||
deflateInit(stream, level);
|
deflateInit(stream, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t zlib_stream_crc32_calculate(uint32_t crc,
|
static uint32_t zlib_stream_crc32_calculate(uint32_t crc,
|
||||||
const uint8_t *data, size_t length)
|
const uint8_t *data, size_t length)
|
||||||
{
|
{
|
||||||
return crc32(crc, data, length);
|
return crc32(crc, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct file_archive_file_backend zlib_backend = {
|
const struct file_archive_file_backend zlib_backend = {
|
||||||
zlib_stream_new,
|
zlib_stream_new,
|
||||||
zlib_stream_free,
|
zlib_stream_free,
|
||||||
zlib_stream_set,
|
zlib_stream_set,
|
||||||
zlib_stream_get_avail_in,
|
zlib_stream_get_avail_in,
|
||||||
zlib_stream_get_avail_out,
|
zlib_stream_get_avail_out,
|
||||||
zlib_stream_get_total_out,
|
zlib_stream_get_total_out,
|
||||||
zlib_stream_decrement_total_out,
|
zlib_stream_decrement_total_out,
|
||||||
zlib_stream_decompress_init,
|
zlib_stream_decompress_init,
|
||||||
zlib_stream_decompress_data_to_file_init,
|
zlib_stream_decompress_data_to_file_init,
|
||||||
zlib_stream_decompress_data_to_file_iterate,
|
zlib_stream_decompress_data_to_file_iterate,
|
||||||
zlib_stream_compress_init,
|
zlib_stream_compress_init,
|
||||||
zlib_stream_compress_free,
|
zlib_stream_compress_free,
|
||||||
zlib_stream_compress_data_to_file,
|
zlib_stream_compress_data_to_file,
|
||||||
zlib_stream_crc32_calculate,
|
zlib_stream_crc32_calculate,
|
||||||
"zlib"
|
"zlib"
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,53 +1,53 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1995, 1999
|
* Copyright (c) 1995, 1999
|
||||||
* Berkeley Software Design, Inc. All rights reserved.
|
* Berkeley Software Design, Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
|
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
|
* ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
|
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _IFADDRS_H_
|
#ifndef _IFADDRS_H_
|
||||||
#define _IFADDRS_H_
|
#define _IFADDRS_H_
|
||||||
|
|
||||||
struct ifaddrs
|
struct ifaddrs
|
||||||
{
|
{
|
||||||
struct ifaddrs *ifa_next;
|
struct ifaddrs *ifa_next;
|
||||||
char *ifa_name;
|
char *ifa_name;
|
||||||
unsigned int ifa_flags;
|
unsigned int ifa_flags;
|
||||||
struct sockaddr *ifa_addr;
|
struct sockaddr *ifa_addr;
|
||||||
struct sockaddr *ifa_netmask;
|
struct sockaddr *ifa_netmask;
|
||||||
struct sockaddr *ifa_dstaddr;
|
struct sockaddr *ifa_dstaddr;
|
||||||
void *ifa_data;
|
void *ifa_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This may have been defined in <net/if.h>. Note that if <net/if.h> is
|
* This may have been defined in <net/if.h>. Note that if <net/if.h> is
|
||||||
* to be included it must be included before this header file.
|
* to be included it must be included before this header file.
|
||||||
*/
|
*/
|
||||||
#ifndef ifa_broadaddr
|
#ifndef ifa_broadaddr
|
||||||
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
|
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
extern int getifaddrs(struct ifaddrs **ifap);
|
extern int getifaddrs(struct ifaddrs **ifap);
|
||||||
extern void freeifaddrs(struct ifaddrs *ifa);
|
extern void freeifaddrs(struct ifaddrs *ifa);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,138 +1,138 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (archive_file.h).
|
* The following license statement only applies to this file (archive_file.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBRETRO_SDK_ARCHIVE_FILE_H__
|
#ifndef LIBRETRO_SDK_ARCHIVE_FILE_H__
|
||||||
#define LIBRETRO_SDK_ARCHIVE_FILE_H__
|
#define LIBRETRO_SDK_ARCHIVE_FILE_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
enum file_archive_transfer_type
|
enum file_archive_transfer_type
|
||||||
{
|
{
|
||||||
ZLIB_TRANSFER_NONE = 0,
|
ZLIB_TRANSFER_NONE = 0,
|
||||||
ZLIB_TRANSFER_INIT,
|
ZLIB_TRANSFER_INIT,
|
||||||
ZLIB_TRANSFER_ITERATE,
|
ZLIB_TRANSFER_ITERATE,
|
||||||
ZLIB_TRANSFER_DEINIT,
|
ZLIB_TRANSFER_DEINIT,
|
||||||
ZLIB_TRANSFER_DEINIT_ERROR
|
ZLIB_TRANSFER_DEINIT_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct file_archive_handle
|
typedef struct file_archive_handle
|
||||||
{
|
{
|
||||||
void *stream;
|
void *stream;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
uint32_t real_checksum;
|
uint32_t real_checksum;
|
||||||
const struct file_archive_file_backend *backend;
|
const struct file_archive_file_backend *backend;
|
||||||
} file_archive_file_handle_t;
|
} file_archive_file_handle_t;
|
||||||
|
|
||||||
struct file_archive_file_backend
|
struct file_archive_file_backend
|
||||||
{
|
{
|
||||||
void *(*stream_new)(void);
|
void *(*stream_new)(void);
|
||||||
void (*stream_free)(void *);
|
void (*stream_free)(void *);
|
||||||
void (*stream_set)(void *, uint32_t, uint32_t,
|
void (*stream_set)(void *, uint32_t, uint32_t,
|
||||||
const uint8_t *, uint8_t *);
|
const uint8_t *, uint8_t *);
|
||||||
uint32_t (*stream_get_avail_in)(void*);
|
uint32_t (*stream_get_avail_in)(void*);
|
||||||
uint32_t (*stream_get_avail_out)(void*);
|
uint32_t (*stream_get_avail_out)(void*);
|
||||||
uint64_t (*stream_get_total_out)(void*);
|
uint64_t (*stream_get_total_out)(void*);
|
||||||
void (*stream_decrement_total_out)(void *, unsigned);
|
void (*stream_decrement_total_out)(void *, unsigned);
|
||||||
bool (*stream_decompress_init)(void *);
|
bool (*stream_decompress_init)(void *);
|
||||||
bool (*stream_decompress_data_to_file_init)(
|
bool (*stream_decompress_data_to_file_init)(
|
||||||
file_archive_file_handle_t *, const uint8_t *, uint32_t, uint32_t);
|
file_archive_file_handle_t *, const uint8_t *, uint32_t, uint32_t);
|
||||||
int (*stream_decompress_data_to_file_iterate)(void *);
|
int (*stream_decompress_data_to_file_iterate)(void *);
|
||||||
void (*stream_compress_init)(void *, int);
|
void (*stream_compress_init)(void *, int);
|
||||||
void (*stream_compress_free)(void *);
|
void (*stream_compress_free)(void *);
|
||||||
int (*stream_compress_data_to_file)(void *);
|
int (*stream_compress_data_to_file)(void *);
|
||||||
uint32_t (*stream_crc_calculate)(uint32_t, const uint8_t *, size_t);
|
uint32_t (*stream_crc_calculate)(uint32_t, const uint8_t *, size_t);
|
||||||
const char *ident;
|
const char *ident;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct file_archive_transfer
|
typedef struct file_archive_transfer
|
||||||
{
|
{
|
||||||
void *handle;
|
void *handle;
|
||||||
const uint8_t *footer;
|
const uint8_t *footer;
|
||||||
const uint8_t *directory;
|
const uint8_t *directory;
|
||||||
const uint8_t *data;
|
const uint8_t *data;
|
||||||
int32_t zip_size;
|
int32_t zip_size;
|
||||||
enum file_archive_transfer_type type;
|
enum file_archive_transfer_type type;
|
||||||
const struct file_archive_file_backend *backend;
|
const struct file_archive_file_backend *backend;
|
||||||
} file_archive_transfer_t;
|
} file_archive_transfer_t;
|
||||||
|
|
||||||
|
|
||||||
/* Returns true when parsing should continue. False to stop. */
|
/* Returns true when parsing should continue. False to stop. */
|
||||||
typedef int (*file_archive_file_cb)(const char *name, const char *valid_exts,
|
typedef int (*file_archive_file_cb)(const char *name, const char *valid_exts,
|
||||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||||
uint32_t crc32, void *userdata);
|
uint32_t crc32, void *userdata);
|
||||||
|
|
||||||
int file_archive_parse_file_iterate(
|
int file_archive_parse_file_iterate(
|
||||||
file_archive_transfer_t *state,
|
file_archive_transfer_t *state,
|
||||||
bool *returnerr,
|
bool *returnerr,
|
||||||
const char *file,
|
const char *file,
|
||||||
const char *valid_exts,
|
const char *valid_exts,
|
||||||
file_archive_file_cb file_cb,
|
file_archive_file_cb file_cb,
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
void file_archive_parse_file_iterate_stop(file_archive_transfer_t *state);
|
void file_archive_parse_file_iterate_stop(file_archive_transfer_t *state);
|
||||||
|
|
||||||
int file_archive_parse_file_progress(file_archive_transfer_t *state);
|
int file_archive_parse_file_progress(file_archive_transfer_t *state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* file_archive_extract_first_content_file:
|
* file_archive_extract_first_content_file:
|
||||||
* @zip_path : filename path to ZIP archive.
|
* @zip_path : filename path to ZIP archive.
|
||||||
* @zip_path_size : size of ZIP archive.
|
* @zip_path_size : size of ZIP archive.
|
||||||
* @valid_exts : valid extensions for a content file.
|
* @valid_exts : valid extensions for a content file.
|
||||||
* @extraction_directory : the directory to extract temporary
|
* @extraction_directory : the directory to extract temporary
|
||||||
* unzipped content to.
|
* unzipped content to.
|
||||||
*
|
*
|
||||||
* Extract first content file from archive.
|
* Extract first content file from archive.
|
||||||
*
|
*
|
||||||
* Returns : true (1) on success, otherwise false (0).
|
* Returns : true (1) on success, otherwise false (0).
|
||||||
**/
|
**/
|
||||||
bool file_archive_extract_first_content_file(char *zip_path, size_t zip_path_size,
|
bool file_archive_extract_first_content_file(char *zip_path, size_t zip_path_size,
|
||||||
const char *valid_exts, const char *extraction_dir,
|
const char *valid_exts, const char *extraction_dir,
|
||||||
char *out_path, size_t len);
|
char *out_path, size_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* file_archive_get_file_list:
|
* file_archive_get_file_list:
|
||||||
* @path : filename path of archive
|
* @path : filename path of archive
|
||||||
* @valid_exts : Valid extensions of archive to be parsed.
|
* @valid_exts : Valid extensions of archive to be parsed.
|
||||||
* If NULL, allow all.
|
* If NULL, allow all.
|
||||||
*
|
*
|
||||||
* Returns: string listing of files from archive on success, otherwise NULL.
|
* Returns: string listing of files from archive on success, otherwise NULL.
|
||||||
**/
|
**/
|
||||||
struct string_list *file_archive_get_file_list(const char *path, const char *valid_exts);
|
struct string_list *file_archive_get_file_list(const char *path, const char *valid_exts);
|
||||||
|
|
||||||
bool file_archive_perform_mode(const char *name, const char *valid_exts,
|
bool file_archive_perform_mode(const char *name, const char *valid_exts,
|
||||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||||
uint32_t crc32, void *userdata);
|
uint32_t crc32, void *userdata);
|
||||||
|
|
||||||
struct string_list *compressed_file_list_new(const char *filename,
|
struct string_list *compressed_file_list_new(const char *filename,
|
||||||
const char* ext);
|
const char* ext);
|
||||||
|
|
||||||
void file_archive_deflate_init(void *data, int level);
|
void file_archive_deflate_init(void *data, int level);
|
||||||
|
|
||||||
const struct file_archive_file_backend *file_archive_get_default_file_backend(void);
|
const struct file_archive_file_backend *file_archive_get_default_file_backend(void);
|
||||||
|
|
||||||
extern const struct file_archive_file_backend zlib_backend;
|
extern const struct file_archive_file_backend zlib_backend;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,70 +1,70 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (dir_list.h).
|
* The following license statement only applies to this file (dir_list.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LIBRETRO_SDK_DIR_LIST_H
|
#ifndef __LIBRETRO_SDK_DIR_LIST_H
|
||||||
#define __LIBRETRO_SDK_DIR_LIST_H
|
#define __LIBRETRO_SDK_DIR_LIST_H
|
||||||
|
|
||||||
#include <lists/string_list.h>
|
#include <lists/string_list.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dir_list_new:
|
* dir_list_new:
|
||||||
* @dir : directory path.
|
* @dir : directory path.
|
||||||
* @ext : allowed extensions of file directory entries to include.
|
* @ext : allowed extensions of file directory entries to include.
|
||||||
* @include_dirs : include directories as part of the finished directory listing?
|
* @include_dirs : include directories as part of the finished directory listing?
|
||||||
* @include_compressed : include compressed files, even when not part of ext.
|
* @include_compressed : include compressed files, even when not part of ext.
|
||||||
*
|
*
|
||||||
* Create a directory listing.
|
* Create a directory listing.
|
||||||
*
|
*
|
||||||
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
|
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
|
||||||
* NULL in case of error. Has to be freed manually.
|
* NULL in case of error. Has to be freed manually.
|
||||||
**/
|
**/
|
||||||
struct string_list *dir_list_new(const char *dir, const char *ext,
|
struct string_list *dir_list_new(const char *dir, const char *ext,
|
||||||
bool include_dirs, bool include_compressed);
|
bool include_dirs, bool include_compressed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dir_list_sort:
|
* dir_list_sort:
|
||||||
* @list : pointer to the directory listing.
|
* @list : pointer to the directory listing.
|
||||||
* @dir_first : move the directories in the listing to the top?
|
* @dir_first : move the directories in the listing to the top?
|
||||||
*
|
*
|
||||||
* Sorts a directory listing.
|
* Sorts a directory listing.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
void dir_list_sort(struct string_list *list, bool dir_first);
|
void dir_list_sort(struct string_list *list, bool dir_first);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dir_list_free:
|
* dir_list_free:
|
||||||
* @list : pointer to the directory listing
|
* @list : pointer to the directory listing
|
||||||
*
|
*
|
||||||
* Frees a directory listing.
|
* Frees a directory listing.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
void dir_list_free(struct string_list *list);
|
void dir_list_free(struct string_list *list);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,119 +1,119 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (file_list.h).
|
* The following license statement only applies to this file (file_list.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LIBRETRO_SDK_FILE_LIST_H__
|
#ifndef __LIBRETRO_SDK_FILE_LIST_H__
|
||||||
#define __LIBRETRO_SDK_FILE_LIST_H__
|
#define __LIBRETRO_SDK_FILE_LIST_H__
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
struct item_file
|
struct item_file
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
char *label;
|
char *label;
|
||||||
char *alt;
|
char *alt;
|
||||||
unsigned type;
|
unsigned type;
|
||||||
size_t directory_ptr;
|
size_t directory_ptr;
|
||||||
size_t entry_idx;
|
size_t entry_idx;
|
||||||
void *userdata;
|
void *userdata;
|
||||||
void *actiondata;
|
void *actiondata;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct file_list
|
typedef struct file_list
|
||||||
{
|
{
|
||||||
struct item_file *list;
|
struct item_file *list;
|
||||||
|
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
size_t size;
|
size_t size;
|
||||||
} file_list_t;
|
} file_list_t;
|
||||||
|
|
||||||
|
|
||||||
void *file_list_get_userdata_at_offset(const file_list_t *list,
|
void *file_list_get_userdata_at_offset(const file_list_t *list,
|
||||||
size_t index);
|
size_t index);
|
||||||
|
|
||||||
void *file_list_get_actiondata_at_offset(const file_list_t *list,
|
void *file_list_get_actiondata_at_offset(const file_list_t *list,
|
||||||
size_t index);
|
size_t index);
|
||||||
|
|
||||||
void file_list_free(file_list_t *list);
|
void file_list_free(file_list_t *list);
|
||||||
|
|
||||||
bool file_list_push(file_list_t *userdata, const char *path,
|
bool file_list_push(file_list_t *userdata, const char *path,
|
||||||
const char *label, unsigned type, size_t current_directory_ptr,
|
const char *label, unsigned type, size_t current_directory_ptr,
|
||||||
size_t entry_index);
|
size_t entry_index);
|
||||||
|
|
||||||
void file_list_pop(file_list_t *list, size_t *directory_ptr);
|
void file_list_pop(file_list_t *list, size_t *directory_ptr);
|
||||||
|
|
||||||
void file_list_clear(file_list_t *list);
|
void file_list_clear(file_list_t *list);
|
||||||
|
|
||||||
void file_list_copy(const file_list_t *src, file_list_t *dst);
|
void file_list_copy(const file_list_t *src, file_list_t *dst);
|
||||||
|
|
||||||
void file_list_get_last(const file_list_t *list,
|
void file_list_get_last(const file_list_t *list,
|
||||||
const char **path, const char **label,
|
const char **path, const char **label,
|
||||||
unsigned *type, size_t *entry_idx);
|
unsigned *type, size_t *entry_idx);
|
||||||
|
|
||||||
void *file_list_get_last_actiondata(const file_list_t *list);
|
void *file_list_get_last_actiondata(const file_list_t *list);
|
||||||
|
|
||||||
size_t file_list_get_size(const file_list_t *list);
|
size_t file_list_get_size(const file_list_t *list);
|
||||||
|
|
||||||
size_t file_list_get_directory_ptr(const file_list_t *list);
|
size_t file_list_get_directory_ptr(const file_list_t *list);
|
||||||
|
|
||||||
void file_list_get_at_offset(const file_list_t *list, size_t index,
|
void file_list_get_at_offset(const file_list_t *list, size_t index,
|
||||||
const char **path, const char **label,
|
const char **path, const char **label,
|
||||||
unsigned *type, size_t *entry_idx);
|
unsigned *type, size_t *entry_idx);
|
||||||
|
|
||||||
void file_list_free_userdata(const file_list_t *list, size_t index);
|
void file_list_free_userdata(const file_list_t *list, size_t index);
|
||||||
|
|
||||||
void file_list_free_actiondata(const file_list_t *list, size_t idx);
|
void file_list_free_actiondata(const file_list_t *list, size_t idx);
|
||||||
|
|
||||||
void file_list_set_label_at_offset(file_list_t *list, size_t index,
|
void file_list_set_label_at_offset(file_list_t *list, size_t index,
|
||||||
const char *label);
|
const char *label);
|
||||||
|
|
||||||
void file_list_get_label_at_offset(const file_list_t *list, size_t index,
|
void file_list_get_label_at_offset(const file_list_t *list, size_t index,
|
||||||
const char **label);
|
const char **label);
|
||||||
|
|
||||||
void file_list_set_alt_at_offset(file_list_t *list, size_t index,
|
void file_list_set_alt_at_offset(file_list_t *list, size_t index,
|
||||||
const char *alt);
|
const char *alt);
|
||||||
|
|
||||||
void file_list_set_userdata(const file_list_t *list, size_t idx, void *ptr);
|
void file_list_set_userdata(const file_list_t *list, size_t idx, void *ptr);
|
||||||
|
|
||||||
void file_list_set_actiondata(const file_list_t *list, size_t idx, void *ptr);
|
void file_list_set_actiondata(const file_list_t *list, size_t idx, void *ptr);
|
||||||
|
|
||||||
void file_list_get_alt_at_offset(const file_list_t *list, size_t index,
|
void file_list_get_alt_at_offset(const file_list_t *list, size_t index,
|
||||||
const char **alt);
|
const char **alt);
|
||||||
|
|
||||||
void file_list_sort_on_alt(file_list_t *list);
|
void file_list_sort_on_alt(file_list_t *list);
|
||||||
|
|
||||||
void file_list_sort_on_type(file_list_t *list);
|
void file_list_sort_on_type(file_list_t *list);
|
||||||
|
|
||||||
bool file_list_search(const file_list_t *list, const char *needle,
|
bool file_list_search(const file_list_t *list, const char *needle,
|
||||||
size_t *index);
|
size_t *index);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,148 +1,148 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (string_list.h).
|
* The following license statement only applies to this file (string_list.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LIBRETRO_SDK_STRING_LIST_H
|
#ifndef __LIBRETRO_SDK_STRING_LIST_H
|
||||||
#define __LIBRETRO_SDK_STRING_LIST_H
|
#define __LIBRETRO_SDK_STRING_LIST_H
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
union string_list_elem_attr
|
union string_list_elem_attr
|
||||||
{
|
{
|
||||||
bool b;
|
bool b;
|
||||||
int i;
|
int i;
|
||||||
void *p;
|
void *p;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct string_list_elem
|
struct string_list_elem
|
||||||
{
|
{
|
||||||
char *data;
|
char *data;
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct string_list
|
struct string_list
|
||||||
{
|
{
|
||||||
struct string_list_elem *elems;
|
struct string_list_elem *elems;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t cap;
|
size_t cap;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_find_elem:
|
* string_list_find_elem:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @elem : element to find inside the string list.
|
* @elem : element to find inside the string list.
|
||||||
*
|
*
|
||||||
* Searches for an element (@elem) inside the string list.
|
* Searches for an element (@elem) inside the string list.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if element could be found, otherwise false (0).
|
* Returns: true (1) if element could be found, otherwise false (0).
|
||||||
*/
|
*/
|
||||||
int string_list_find_elem(const struct string_list *list, const char *elem);
|
int string_list_find_elem(const struct string_list *list, const char *elem);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_find_elem_prefix:
|
* string_list_find_elem_prefix:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @prefix : prefix to append to @elem
|
* @prefix : prefix to append to @elem
|
||||||
* @elem : element to find inside the string list.
|
* @elem : element to find inside the string list.
|
||||||
*
|
*
|
||||||
* Searches for an element (@elem) inside the string list. Will
|
* Searches for an element (@elem) inside the string list. Will
|
||||||
* also search for the same element prefixed by @prefix.
|
* also search for the same element prefixed by @prefix.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if element could be found, otherwise false (0).
|
* Returns: true (1) if element could be found, otherwise false (0).
|
||||||
*/
|
*/
|
||||||
bool string_list_find_elem_prefix(const struct string_list *list,
|
bool string_list_find_elem_prefix(const struct string_list *list,
|
||||||
const char *prefix, const char *elem);
|
const char *prefix, const char *elem);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_split:
|
* string_split:
|
||||||
* @str : string to turn into a string list
|
* @str : string to turn into a string list
|
||||||
* @delim : delimiter character to use for splitting the string.
|
* @delim : delimiter character to use for splitting the string.
|
||||||
*
|
*
|
||||||
* Creates a new string list based on string @str, delimited by @delim.
|
* Creates a new string list based on string @str, delimited by @delim.
|
||||||
*
|
*
|
||||||
* Returns: new string list if successful, otherwise NULL.
|
* Returns: new string list if successful, otherwise NULL.
|
||||||
*/
|
*/
|
||||||
struct string_list *string_split(const char *str, const char *delim);
|
struct string_list *string_split(const char *str, const char *delim);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_new:
|
* string_list_new:
|
||||||
*
|
*
|
||||||
* Creates a new string list. Has to be freed manually.
|
* Creates a new string list. Has to be freed manually.
|
||||||
*
|
*
|
||||||
* Returns: new string list if successful, otherwise NULL.
|
* Returns: new string list if successful, otherwise NULL.
|
||||||
*/
|
*/
|
||||||
struct string_list *string_list_new(void);
|
struct string_list *string_list_new(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_append:
|
* string_list_append:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @elem : element to add to the string list
|
* @elem : element to add to the string list
|
||||||
* @attr : attributes of new element.
|
* @attr : attributes of new element.
|
||||||
*
|
*
|
||||||
* Appends a new element to the string list.
|
* Appends a new element to the string list.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if successful, otherwise false (0).
|
* Returns: true (1) if successful, otherwise false (0).
|
||||||
**/
|
**/
|
||||||
bool string_list_append(struct string_list *list, const char *elem,
|
bool string_list_append(struct string_list *list, const char *elem,
|
||||||
union string_list_elem_attr attr);
|
union string_list_elem_attr attr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_free
|
* string_list_free
|
||||||
* @list : pointer to string list object
|
* @list : pointer to string list object
|
||||||
*
|
*
|
||||||
* Frees a string list.
|
* Frees a string list.
|
||||||
*/
|
*/
|
||||||
void string_list_free(struct string_list *list);
|
void string_list_free(struct string_list *list);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_join_concat:
|
* string_list_join_concat:
|
||||||
* @buffer : buffer that @list will be joined to.
|
* @buffer : buffer that @list will be joined to.
|
||||||
* @size : length of @buffer.
|
* @size : length of @buffer.
|
||||||
* @list : pointer to string list.
|
* @list : pointer to string list.
|
||||||
* @delim : delimiter character for @list.
|
* @delim : delimiter character for @list.
|
||||||
*
|
*
|
||||||
* A string list will be joined/concatenated as a
|
* A string list will be joined/concatenated as a
|
||||||
* string to @buffer, delimited by @delim.
|
* string to @buffer, delimited by @delim.
|
||||||
*/
|
*/
|
||||||
void string_list_join_concat(char *buffer, size_t size,
|
void string_list_join_concat(char *buffer, size_t size,
|
||||||
const struct string_list *list, const char *sep);
|
const struct string_list *list, const char *sep);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_set:
|
* string_list_set:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @idx : index of element in string list
|
* @idx : index of element in string list
|
||||||
* @str : value for the element.
|
* @str : value for the element.
|
||||||
*
|
*
|
||||||
* Set value of element inside string list.
|
* Set value of element inside string list.
|
||||||
**/
|
**/
|
||||||
void string_list_set(struct string_list *list, unsigned idx,
|
void string_list_set(struct string_list *list, unsigned idx,
|
||||||
const char *str);
|
const char *str);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,49 +1,49 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (net_ifinfo.h).
|
* The following license statement only applies to this file (net_ifinfo.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _LIBRETRO_NET_IFINFO_H
|
#ifndef _LIBRETRO_NET_IFINFO_H
|
||||||
#define _LIBRETRO_NET_IFINFO_H
|
#define _LIBRETRO_NET_IFINFO_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
struct net_ifinfo_entry
|
struct net_ifinfo_entry
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
char *host;
|
char *host;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct net_ifinfo
|
struct net_ifinfo
|
||||||
{
|
{
|
||||||
struct net_ifinfo_entry *entries;
|
struct net_ifinfo_entry *entries;
|
||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct net_ifinfo net_ifinfo_t;
|
typedef struct net_ifinfo net_ifinfo_t;
|
||||||
|
|
||||||
void net_ifinfo_free(net_ifinfo_t *list);
|
void net_ifinfo_free(net_ifinfo_t *list);
|
||||||
|
|
||||||
bool net_ifinfo_new(net_ifinfo_t *list);
|
bool net_ifinfo_new(net_ifinfo_t *list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (fifo_queue.h).
|
* The following license statement only applies to this file (fifo_queue.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LIBRETRO_SDK_FIFO_BUFFER_H
|
#ifndef __LIBRETRO_SDK_FIFO_BUFFER_H
|
||||||
#define __LIBRETRO_SDK_FIFO_BUFFER_H
|
#define __LIBRETRO_SDK_FIFO_BUFFER_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct fifo_buffer fifo_buffer_t;
|
typedef struct fifo_buffer fifo_buffer_t;
|
||||||
|
|
||||||
fifo_buffer_t *fifo_new(size_t size);
|
fifo_buffer_t *fifo_new(size_t size);
|
||||||
|
|
||||||
void fifo_clear(fifo_buffer_t *buffer);
|
void fifo_clear(fifo_buffer_t *buffer);
|
||||||
|
|
||||||
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size);
|
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size);
|
||||||
|
|
||||||
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size);
|
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size);
|
||||||
|
|
||||||
void fifo_free(fifo_buffer_t *buffer);
|
void fifo_free(fifo_buffer_t *buffer);
|
||||||
|
|
||||||
size_t fifo_read_avail(fifo_buffer_t *buffer);
|
size_t fifo_read_avail(fifo_buffer_t *buffer);
|
||||||
|
|
||||||
size_t fifo_write_avail(fifo_buffer_t *buffer);
|
size_t fifo_write_avail(fifo_buffer_t *buffer);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,75 +1,75 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (file_stream.h).
|
* The following license statement only applies to this file (file_stream.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LIBRETRO_SDK_FILE_STREAM_H
|
#ifndef __LIBRETRO_SDK_FILE_STREAM_H
|
||||||
#define __LIBRETRO_SDK_FILE_STREAM_H
|
#define __LIBRETRO_SDK_FILE_STREAM_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <retro_common.h>
|
#include <retro_common.h>
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct RFILE RFILE;
|
typedef struct RFILE RFILE;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
RFILE_MODE_READ = 0,
|
RFILE_MODE_READ = 0,
|
||||||
RFILE_MODE_WRITE,
|
RFILE_MODE_WRITE,
|
||||||
RFILE_MODE_READ_WRITE,
|
RFILE_MODE_READ_WRITE,
|
||||||
|
|
||||||
/* There is no garantee these requests will be attended. */
|
/* There is no garantee these requests will be attended. */
|
||||||
RFILE_HINT_UNBUFFERED = 1<<8,
|
RFILE_HINT_UNBUFFERED = 1<<8,
|
||||||
RFILE_HINT_MMAP = 1<<9 /* requires RFILE_MODE_READ */
|
RFILE_HINT_MMAP = 1<<9 /* requires RFILE_MODE_READ */
|
||||||
};
|
};
|
||||||
|
|
||||||
RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len);
|
RFILE *retro_fopen(const char *path, unsigned mode, ssize_t len);
|
||||||
|
|
||||||
ssize_t retro_fseek(RFILE *stream, ssize_t offset, int whence);
|
ssize_t retro_fseek(RFILE *stream, ssize_t offset, int whence);
|
||||||
|
|
||||||
ssize_t retro_fread(RFILE *stream, void *s, size_t len);
|
ssize_t retro_fread(RFILE *stream, void *s, size_t len);
|
||||||
|
|
||||||
ssize_t retro_fwrite(RFILE *stream, const void *s, size_t len);
|
ssize_t retro_fwrite(RFILE *stream, const void *s, size_t len);
|
||||||
|
|
||||||
ssize_t retro_ftell(RFILE *stream);
|
ssize_t retro_ftell(RFILE *stream);
|
||||||
|
|
||||||
void retro_frewind(RFILE *stream);
|
void retro_frewind(RFILE *stream);
|
||||||
|
|
||||||
int retro_fclose(RFILE *stream);
|
int retro_fclose(RFILE *stream);
|
||||||
|
|
||||||
int retro_read_file(const char *path, void **buf, ssize_t *len);
|
int retro_read_file(const char *path, void **buf, ssize_t *len);
|
||||||
|
|
||||||
bool retro_write_file(const char *path, const void *data, ssize_t size);
|
bool retro_write_file(const char *path, const void *data, ssize_t size);
|
||||||
|
|
||||||
int retro_get_fd(RFILE *stream);
|
int retro_get_fd(RFILE *stream);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,51 +1,51 @@
|
||||||
/* Copyright (C) 2010-2015 The RetroArch team
|
/* Copyright (C) 2010-2015 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (memory_stream.h).
|
* The following license statement only applies to this file (memory_stream.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
|
#ifndef _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
|
||||||
#define _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
|
#define _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef struct memstream memstream_t;
|
typedef struct memstream memstream_t;
|
||||||
|
|
||||||
memstream_t *memstream_open(void);
|
memstream_t *memstream_open(void);
|
||||||
|
|
||||||
void memstream_close(memstream_t * stream);
|
void memstream_close(memstream_t * stream);
|
||||||
|
|
||||||
size_t memstream_read(memstream_t * stream, void *data, size_t bytes);
|
size_t memstream_read(memstream_t * stream, void *data, size_t bytes);
|
||||||
|
|
||||||
size_t memstream_write(memstream_t * stream, const void *data, size_t bytes);
|
size_t memstream_write(memstream_t * stream, const void *data, size_t bytes);
|
||||||
|
|
||||||
int memstream_getc(memstream_t * stream);
|
int memstream_getc(memstream_t * stream);
|
||||||
|
|
||||||
char *memstream_gets(memstream_t * stream, char *buffer, size_t len);
|
char *memstream_gets(memstream_t * stream, char *buffer, size_t len);
|
||||||
|
|
||||||
size_t memstream_pos(memstream_t * stream);
|
size_t memstream_pos(memstream_t * stream);
|
||||||
|
|
||||||
int memstream_seek(memstream_t * stream, int offset, int whence);
|
int memstream_seek(memstream_t * stream, int offset, int whence);
|
||||||
|
|
||||||
void memstream_set_buffer(uint8_t *buffer, size_t size);
|
void memstream_set_buffer(uint8_t *buffer, size_t size);
|
||||||
|
|
||||||
size_t memstream_get_last_size(void);
|
size_t memstream_get_last_size(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,214 +1,214 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (dir_list.c).
|
* The following license statement only applies to this file (dir_list.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <lists/dir_list.h>
|
#include <lists/dir_list.h>
|
||||||
#include <lists/string_list.h>
|
#include <lists/string_list.h>
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
|
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
#include <retro_dirent.h>
|
#include <retro_dirent.h>
|
||||||
|
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
|
|
||||||
static int qstrcmp_plain(const void *a_, const void *b_)
|
static int qstrcmp_plain(const void *a_, const void *b_)
|
||||||
{
|
{
|
||||||
const struct string_list_elem *a = (const struct string_list_elem*)a_;
|
const struct string_list_elem *a = (const struct string_list_elem*)a_;
|
||||||
const struct string_list_elem *b = (const struct string_list_elem*)b_;
|
const struct string_list_elem *b = (const struct string_list_elem*)b_;
|
||||||
|
|
||||||
return strcasecmp(a->data, b->data);
|
return strcasecmp(a->data, b->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qstrcmp_dir(const void *a_, const void *b_)
|
static int qstrcmp_dir(const void *a_, const void *b_)
|
||||||
{
|
{
|
||||||
const struct string_list_elem *a = (const struct string_list_elem*)a_;
|
const struct string_list_elem *a = (const struct string_list_elem*)a_;
|
||||||
const struct string_list_elem *b = (const struct string_list_elem*)b_;
|
const struct string_list_elem *b = (const struct string_list_elem*)b_;
|
||||||
int a_type = a->attr.i;
|
int a_type = a->attr.i;
|
||||||
int b_type = b->attr.i;
|
int b_type = b->attr.i;
|
||||||
|
|
||||||
|
|
||||||
/* Sort directories before files. */
|
/* Sort directories before files. */
|
||||||
if (a_type != b_type)
|
if (a_type != b_type)
|
||||||
return b_type - a_type;
|
return b_type - a_type;
|
||||||
return strcasecmp(a->data, b->data);
|
return strcasecmp(a->data, b->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dir_list_sort:
|
* dir_list_sort:
|
||||||
* @list : pointer to the directory listing.
|
* @list : pointer to the directory listing.
|
||||||
* @dir_first : move the directories in the listing to the top?
|
* @dir_first : move the directories in the listing to the top?
|
||||||
*
|
*
|
||||||
* Sorts a directory listing.
|
* Sorts a directory listing.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
void dir_list_sort(struct string_list *list, bool dir_first)
|
void dir_list_sort(struct string_list *list, bool dir_first)
|
||||||
{
|
{
|
||||||
if (list)
|
if (list)
|
||||||
qsort(list->elems, list->size, sizeof(struct string_list_elem),
|
qsort(list->elems, list->size, sizeof(struct string_list_elem),
|
||||||
dir_first ? qstrcmp_dir : qstrcmp_plain);
|
dir_first ? qstrcmp_dir : qstrcmp_plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dir_list_free:
|
* dir_list_free:
|
||||||
* @list : pointer to the directory listing
|
* @list : pointer to the directory listing
|
||||||
*
|
*
|
||||||
* Frees a directory listing.
|
* Frees a directory listing.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
void dir_list_free(struct string_list *list)
|
void dir_list_free(struct string_list *list)
|
||||||
{
|
{
|
||||||
string_list_free(list);
|
string_list_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse_dir_entry:
|
* parse_dir_entry:
|
||||||
* @name : name of the directory listing entry.
|
* @name : name of the directory listing entry.
|
||||||
* @file_path : file path of the directory listing entry.
|
* @file_path : file path of the directory listing entry.
|
||||||
* @is_dir : is the directory listing a directory?
|
* @is_dir : is the directory listing a directory?
|
||||||
* @include_dirs : include directories as part of the finished directory listing?
|
* @include_dirs : include directories as part of the finished directory listing?
|
||||||
* @include_compressed : Include compressed files, even if not part of ext_list.
|
* @include_compressed : Include compressed files, even if not part of ext_list.
|
||||||
* @list : pointer to directory listing.
|
* @list : pointer to directory listing.
|
||||||
* @ext_list : pointer to allowed file extensions listing.
|
* @ext_list : pointer to allowed file extensions listing.
|
||||||
* @file_ext : file extension of the directory listing entry.
|
* @file_ext : file extension of the directory listing entry.
|
||||||
*
|
*
|
||||||
* Parses a directory listing.
|
* Parses a directory listing.
|
||||||
*
|
*
|
||||||
* Returns: zero on success, -1 on error, 1 if we should
|
* Returns: zero on success, -1 on error, 1 if we should
|
||||||
* continue to the next entry in the directory listing.
|
* continue to the next entry in the directory listing.
|
||||||
**/
|
**/
|
||||||
static int parse_dir_entry(const char *name, char *file_path,
|
static int parse_dir_entry(const char *name, char *file_path,
|
||||||
bool is_dir, bool include_dirs, bool include_compressed,
|
bool is_dir, bool include_dirs, bool include_compressed,
|
||||||
struct string_list *list, struct string_list *ext_list,
|
struct string_list *list, struct string_list *ext_list,
|
||||||
const char *file_ext)
|
const char *file_ext)
|
||||||
{
|
{
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
bool is_compressed_file = false;
|
bool is_compressed_file = false;
|
||||||
bool supported_by_core = false;
|
bool supported_by_core = false;
|
||||||
|
|
||||||
attr.i = RARCH_FILETYPE_UNSET;
|
attr.i = RARCH_FILETYPE_UNSET;
|
||||||
|
|
||||||
if (!is_dir)
|
if (!is_dir)
|
||||||
{
|
{
|
||||||
is_compressed_file = path_is_compressed_file(file_path);
|
is_compressed_file = path_is_compressed_file(file_path);
|
||||||
if (string_list_find_elem_prefix(ext_list, ".", file_ext))
|
if (string_list_find_elem_prefix(ext_list, ".", file_ext))
|
||||||
supported_by_core = true;
|
supported_by_core = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!include_dirs && is_dir)
|
if (!include_dirs && is_dir)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!strcmp(name, ".") || !strcmp(name, ".."))
|
if (!strcmp(name, ".") || !strcmp(name, ".."))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!is_dir && ext_list &&
|
if (!is_dir && ext_list &&
|
||||||
((!is_compressed_file && !supported_by_core) ||
|
((!is_compressed_file && !supported_by_core) ||
|
||||||
(!supported_by_core && !include_compressed)))
|
(!supported_by_core && !include_compressed)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (is_dir)
|
if (is_dir)
|
||||||
attr.i = RARCH_DIRECTORY;
|
attr.i = RARCH_DIRECTORY;
|
||||||
if (is_compressed_file)
|
if (is_compressed_file)
|
||||||
attr.i = RARCH_COMPRESSED_ARCHIVE;
|
attr.i = RARCH_COMPRESSED_ARCHIVE;
|
||||||
/* The order of these ifs is important.
|
/* The order of these ifs is important.
|
||||||
* If the file format is explicitly supported by the libretro-core, we
|
* If the file format is explicitly supported by the libretro-core, we
|
||||||
* need to immediately load it and not designate it as a compressed file.
|
* need to immediately load it and not designate it as a compressed file.
|
||||||
*
|
*
|
||||||
* Example: .zip could be supported as a image by the core and as a
|
* Example: .zip could be supported as a image by the core and as a
|
||||||
* compressed_file. In that case, we have to interpret it as a image.
|
* compressed_file. In that case, we have to interpret it as a image.
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
if (supported_by_core)
|
if (supported_by_core)
|
||||||
attr.i = RARCH_PLAIN_FILE;
|
attr.i = RARCH_PLAIN_FILE;
|
||||||
|
|
||||||
if (!string_list_append(list, file_path, attr))
|
if (!string_list_append(list, file_path, attr))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dir_list_new:
|
* dir_list_new:
|
||||||
* @dir : directory path.
|
* @dir : directory path.
|
||||||
* @ext : allowed extensions of file directory entries to include.
|
* @ext : allowed extensions of file directory entries to include.
|
||||||
* @include_dirs : include directories as part of the finished directory listing?
|
* @include_dirs : include directories as part of the finished directory listing?
|
||||||
* @include_compressed : Only include files which match ext. Do not try to match compressed files, etc.
|
* @include_compressed : Only include files which match ext. Do not try to match compressed files, etc.
|
||||||
*
|
*
|
||||||
* Create a directory listing.
|
* Create a directory listing.
|
||||||
*
|
*
|
||||||
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
|
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
|
||||||
* NULL in case of error. Has to be freed manually.
|
* NULL in case of error. Has to be freed manually.
|
||||||
**/
|
**/
|
||||||
struct string_list *dir_list_new(const char *dir,
|
struct string_list *dir_list_new(const char *dir,
|
||||||
const char *ext, bool include_dirs, bool include_compressed)
|
const char *ext, bool include_dirs, bool include_compressed)
|
||||||
{
|
{
|
||||||
struct RDIR *entry = NULL;
|
struct RDIR *entry = NULL;
|
||||||
struct string_list *ext_list = NULL;
|
struct string_list *ext_list = NULL;
|
||||||
struct string_list *list = NULL;
|
struct string_list *list = NULL;
|
||||||
|
|
||||||
if (!(list = string_list_new()))
|
if (!(list = string_list_new()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ext)
|
if (ext)
|
||||||
ext_list = string_split(ext, "|");
|
ext_list = string_split(ext, "|");
|
||||||
|
|
||||||
entry = retro_opendir(dir);
|
entry = retro_opendir(dir);
|
||||||
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (retro_dirent_error(entry))
|
if (retro_dirent_error(entry))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
while (retro_readdir(entry))
|
while (retro_readdir(entry))
|
||||||
{
|
{
|
||||||
char file_path[PATH_MAX_LENGTH];
|
char file_path[PATH_MAX_LENGTH];
|
||||||
bool is_dir;
|
bool is_dir;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
const char *name = retro_dirent_get_name(entry);
|
const char *name = retro_dirent_get_name(entry);
|
||||||
const char *file_ext = path_get_extension(name);
|
const char *file_ext = path_get_extension(name);
|
||||||
|
|
||||||
fill_pathname_join(file_path, dir, name, sizeof(file_path));
|
fill_pathname_join(file_path, dir, name, sizeof(file_path));
|
||||||
is_dir = retro_dirent_is_dir(entry, file_path);
|
is_dir = retro_dirent_is_dir(entry, file_path);
|
||||||
|
|
||||||
ret = parse_dir_entry(name, file_path, is_dir,
|
ret = parse_dir_entry(name, file_path, is_dir,
|
||||||
include_dirs, include_compressed, list, ext_list, file_ext);
|
include_dirs, include_compressed, list, ext_list, file_ext);
|
||||||
|
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (ret == 1)
|
if (ret == 1)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
retro_closedir(entry);
|
retro_closedir(entry);
|
||||||
|
|
||||||
string_list_free(ext_list);
|
string_list_free(ext_list);
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
retro_closedir(entry);
|
retro_closedir(entry);
|
||||||
|
|
||||||
string_list_free(list);
|
string_list_free(list);
|
||||||
string_list_free(ext_list);
|
string_list_free(ext_list);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,428 +1,428 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (file_list.c).
|
* The following license statement only applies to this file (file_list.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <retro_assert.h>
|
#include <retro_assert.h>
|
||||||
#include <retro_common.h>
|
#include <retro_common.h>
|
||||||
#include <lists/file_list.h>
|
#include <lists/file_list.h>
|
||||||
#include <compat/strcasestr.h>
|
#include <compat/strcasestr.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* file_list_capacity:
|
* file_list_capacity:
|
||||||
* @list : pointer to file list
|
* @list : pointer to file list
|
||||||
* @cap : new capacity for file list.
|
* @cap : new capacity for file list.
|
||||||
*
|
*
|
||||||
* Change maximum capacity of file list's size.
|
* Change maximum capacity of file list's size.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if successful, otherwise false (0).
|
* Returns: true (1) if successful, otherwise false (0).
|
||||||
**/
|
**/
|
||||||
static bool file_list_capacity(file_list_t *list, size_t cap)
|
static bool file_list_capacity(file_list_t *list, size_t cap)
|
||||||
{
|
{
|
||||||
struct item_file *new_data = NULL;
|
struct item_file *new_data = NULL;
|
||||||
retro_assert(cap > list->size);
|
retro_assert(cap > list->size);
|
||||||
|
|
||||||
new_data = (struct item_file*)realloc(list->list,
|
new_data = (struct item_file*)realloc(list->list,
|
||||||
cap * sizeof(struct item_file));
|
cap * sizeof(struct item_file));
|
||||||
|
|
||||||
if (!new_data)
|
if (!new_data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (cap > list->capacity)
|
if (cap > list->capacity)
|
||||||
memset(&new_data[list->capacity], 0,
|
memset(&new_data[list->capacity], 0,
|
||||||
sizeof(*new_data) * (cap - list->capacity));
|
sizeof(*new_data) * (cap - list->capacity));
|
||||||
|
|
||||||
list->list = new_data;
|
list->list = new_data;
|
||||||
list->capacity = cap;
|
list->capacity = cap;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_list_push(file_list_t *list,
|
bool file_list_push(file_list_t *list,
|
||||||
const char *path, const char *label,
|
const char *path, const char *label,
|
||||||
unsigned type, size_t directory_ptr,
|
unsigned type, size_t directory_ptr,
|
||||||
size_t entry_idx)
|
size_t entry_idx)
|
||||||
{
|
{
|
||||||
if (list->size >= list->capacity &&
|
if (list->size >= list->capacity &&
|
||||||
!file_list_capacity(list, list->capacity * 2 + 1))
|
!file_list_capacity(list, list->capacity * 2 + 1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
list->list[list->size].label = NULL;
|
list->list[list->size].label = NULL;
|
||||||
list->list[list->size].path = NULL;
|
list->list[list->size].path = NULL;
|
||||||
list->list[list->size].alt = NULL;
|
list->list[list->size].alt = NULL;
|
||||||
list->list[list->size].userdata = NULL;
|
list->list[list->size].userdata = NULL;
|
||||||
list->list[list->size].actiondata = NULL;
|
list->list[list->size].actiondata = NULL;
|
||||||
list->list[list->size].type = type;
|
list->list[list->size].type = type;
|
||||||
list->list[list->size].directory_ptr = directory_ptr;
|
list->list[list->size].directory_ptr = directory_ptr;
|
||||||
list->list[list->size].entry_idx = entry_idx;
|
list->list[list->size].entry_idx = entry_idx;
|
||||||
|
|
||||||
if (label)
|
if (label)
|
||||||
list->list[list->size].label = strdup(label);
|
list->list[list->size].label = strdup(label);
|
||||||
if (path)
|
if (path)
|
||||||
list->list[list->size].path = strdup(path);
|
list->list[list->size].path = strdup(path);
|
||||||
|
|
||||||
list->size++;
|
list->size++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t file_list_get_size(const file_list_t *list)
|
size_t file_list_get_size(const file_list_t *list)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return 0;
|
return 0;
|
||||||
return list->size;
|
return list->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t file_list_get_directory_ptr(const file_list_t *list)
|
size_t file_list_get_directory_ptr(const file_list_t *list)
|
||||||
{
|
{
|
||||||
size_t size = file_list_get_size(list);
|
size_t size = file_list_get_size(list);
|
||||||
return list->list[size].directory_ptr;
|
return list->list[size].directory_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void file_list_pop(file_list_t *list, size_t *directory_ptr)
|
void file_list_pop(file_list_t *list, size_t *directory_ptr)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (list->size != 0)
|
if (list->size != 0)
|
||||||
{
|
{
|
||||||
--list->size;
|
--list->size;
|
||||||
if (list->list[list->size].path)
|
if (list->list[list->size].path)
|
||||||
free(list->list[list->size].path);
|
free(list->list[list->size].path);
|
||||||
list->list[list->size].path = NULL;
|
list->list[list->size].path = NULL;
|
||||||
|
|
||||||
if (list->list[list->size].label)
|
if (list->list[list->size].label)
|
||||||
free(list->list[list->size].label);
|
free(list->list[list->size].label);
|
||||||
list->list[list->size].label = NULL;
|
list->list[list->size].label = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (directory_ptr)
|
if (directory_ptr)
|
||||||
*directory_ptr = list->list[list->size].directory_ptr;
|
*directory_ptr = list->list[list->size].directory_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_free(file_list_t *list)
|
void file_list_free(file_list_t *list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
file_list_free_userdata(list, i);
|
file_list_free_userdata(list, i);
|
||||||
file_list_free_actiondata(list, i);
|
file_list_free_actiondata(list, i);
|
||||||
|
|
||||||
if (list->list[i].path)
|
if (list->list[i].path)
|
||||||
free(list->list[i].path);
|
free(list->list[i].path);
|
||||||
list->list[i].path = NULL;
|
list->list[i].path = NULL;
|
||||||
|
|
||||||
if (list->list[i].label)
|
if (list->list[i].label)
|
||||||
free(list->list[i].label);
|
free(list->list[i].label);
|
||||||
list->list[i].label = NULL;
|
list->list[i].label = NULL;
|
||||||
|
|
||||||
if (list->list[i].alt)
|
if (list->list[i].alt)
|
||||||
free(list->list[i].alt);
|
free(list->list[i].alt);
|
||||||
list->list[i].alt = NULL;
|
list->list[i].alt = NULL;
|
||||||
}
|
}
|
||||||
if (list->list)
|
if (list->list)
|
||||||
free(list->list);
|
free(list->list);
|
||||||
list->list = NULL;
|
list->list = NULL;
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_clear(file_list_t *list)
|
void file_list_clear(file_list_t *list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
if (list->list[i].path)
|
if (list->list[i].path)
|
||||||
free(list->list[i].path);
|
free(list->list[i].path);
|
||||||
list->list[i].path = NULL;
|
list->list[i].path = NULL;
|
||||||
|
|
||||||
if (list->list[i].label)
|
if (list->list[i].label)
|
||||||
free(list->list[i].label);
|
free(list->list[i].label);
|
||||||
list->list[i].label = NULL;
|
list->list[i].label = NULL;
|
||||||
|
|
||||||
if (list->list[i].alt)
|
if (list->list[i].alt)
|
||||||
free(list->list[i].alt);
|
free(list->list[i].alt);
|
||||||
list->list[i].alt = NULL;
|
list->list[i].alt = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->size = 0;
|
list->size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_copy(const file_list_t *src, file_list_t *dst)
|
void file_list_copy(const file_list_t *src, file_list_t *dst)
|
||||||
{
|
{
|
||||||
struct item_file *item;
|
struct item_file *item;
|
||||||
|
|
||||||
if (!src || !dst)
|
if (!src || !dst)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (dst->list)
|
if (dst->list)
|
||||||
{
|
{
|
||||||
for (item = dst->list; item < &dst->list[dst->size]; ++item)
|
for (item = dst->list; item < &dst->list[dst->size]; ++item)
|
||||||
{
|
{
|
||||||
if (item->path)
|
if (item->path)
|
||||||
free(item->path);
|
free(item->path);
|
||||||
|
|
||||||
if (item->label)
|
if (item->label)
|
||||||
free(item->label);
|
free(item->label);
|
||||||
|
|
||||||
if (item->alt)
|
if (item->alt)
|
||||||
free(item->alt);
|
free(item->alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(dst->list);
|
free(dst->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
dst->size = 0;
|
dst->size = 0;
|
||||||
dst->capacity = 0;
|
dst->capacity = 0;
|
||||||
dst->list = (struct item_file*)malloc(src->size * sizeof(struct item_file));
|
dst->list = (struct item_file*)malloc(src->size * sizeof(struct item_file));
|
||||||
|
|
||||||
if (!dst->list)
|
if (!dst->list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dst->size = dst->capacity = src->size;
|
dst->size = dst->capacity = src->size;
|
||||||
|
|
||||||
memcpy(dst->list, src->list, dst->size * sizeof(struct item_file));
|
memcpy(dst->list, src->list, dst->size * sizeof(struct item_file));
|
||||||
|
|
||||||
for (item = dst->list; item < &dst->list[dst->size]; ++item)
|
for (item = dst->list; item < &dst->list[dst->size]; ++item)
|
||||||
{
|
{
|
||||||
if (item->path)
|
if (item->path)
|
||||||
item->path = strdup(item->path);
|
item->path = strdup(item->path);
|
||||||
|
|
||||||
if (item->label)
|
if (item->label)
|
||||||
item->label = strdup(item->label);
|
item->label = strdup(item->label);
|
||||||
|
|
||||||
if (item->alt)
|
if (item->alt)
|
||||||
item->alt = strdup(item->alt);
|
item->alt = strdup(item->alt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_set_label_at_offset(file_list_t *list, size_t idx,
|
void file_list_set_label_at_offset(file_list_t *list, size_t idx,
|
||||||
const char *label)
|
const char *label)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (list->list[idx].label)
|
if (list->list[idx].label)
|
||||||
free(list->list[idx].label);
|
free(list->list[idx].label);
|
||||||
list->list[idx].alt = NULL;
|
list->list[idx].alt = NULL;
|
||||||
|
|
||||||
if (label)
|
if (label)
|
||||||
list->list[idx].label = strdup(label);
|
list->list[idx].label = strdup(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_get_label_at_offset(const file_list_t *list, size_t idx,
|
void file_list_get_label_at_offset(const file_list_t *list, size_t idx,
|
||||||
const char **label)
|
const char **label)
|
||||||
{
|
{
|
||||||
if (!label || !list)
|
if (!label || !list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
*label = list->list[idx].path;
|
*label = list->list[idx].path;
|
||||||
if (list->list[idx].label)
|
if (list->list[idx].label)
|
||||||
*label = list->list[idx].label;
|
*label = list->list[idx].label;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_set_alt_at_offset(file_list_t *list, size_t idx,
|
void file_list_set_alt_at_offset(file_list_t *list, size_t idx,
|
||||||
const char *alt)
|
const char *alt)
|
||||||
{
|
{
|
||||||
if (!list || !alt)
|
if (!list || !alt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (list->list[idx].alt)
|
if (list->list[idx].alt)
|
||||||
free(list->list[idx].alt);
|
free(list->list[idx].alt);
|
||||||
list->list[idx].alt = NULL;
|
list->list[idx].alt = NULL;
|
||||||
|
|
||||||
if (alt)
|
if (alt)
|
||||||
list->list[idx].alt = strdup(alt);
|
list->list[idx].alt = strdup(alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_get_alt_at_offset(const file_list_t *list, size_t idx,
|
void file_list_get_alt_at_offset(const file_list_t *list, size_t idx,
|
||||||
const char **alt)
|
const char **alt)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (alt)
|
if (alt)
|
||||||
*alt = list->list[idx].alt ?
|
*alt = list->list[idx].alt ?
|
||||||
list->list[idx].alt : list->list[idx].path;
|
list->list[idx].alt : list->list[idx].path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int file_list_alt_cmp(const void *a_, const void *b_)
|
static int file_list_alt_cmp(const void *a_, const void *b_)
|
||||||
{
|
{
|
||||||
const struct item_file *a = (const struct item_file*)a_;
|
const struct item_file *a = (const struct item_file*)a_;
|
||||||
const struct item_file *b = (const struct item_file*)b_;
|
const struct item_file *b = (const struct item_file*)b_;
|
||||||
const char *cmp_a = a->alt ? a->alt : a->path;
|
const char *cmp_a = a->alt ? a->alt : a->path;
|
||||||
const char *cmp_b = b->alt ? b->alt : b->path;
|
const char *cmp_b = b->alt ? b->alt : b->path;
|
||||||
return strcasecmp(cmp_a, cmp_b);
|
return strcasecmp(cmp_a, cmp_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int file_list_type_cmp(const void *a_, const void *b_)
|
static int file_list_type_cmp(const void *a_, const void *b_)
|
||||||
{
|
{
|
||||||
const struct item_file *a = (const struct item_file*)a_;
|
const struct item_file *a = (const struct item_file*)a_;
|
||||||
const struct item_file *b = (const struct item_file*)b_;
|
const struct item_file *b = (const struct item_file*)b_;
|
||||||
if (a->type < b->type)
|
if (a->type < b->type)
|
||||||
return -1;
|
return -1;
|
||||||
if (a->type == b->type)
|
if (a->type == b->type)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_sort_on_alt(file_list_t *list)
|
void file_list_sort_on_alt(file_list_t *list)
|
||||||
{
|
{
|
||||||
qsort(list->list, list->size, sizeof(list->list[0]), file_list_alt_cmp);
|
qsort(list->list, list->size, sizeof(list->list[0]), file_list_alt_cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_sort_on_type(file_list_t *list)
|
void file_list_sort_on_type(file_list_t *list)
|
||||||
{
|
{
|
||||||
qsort(list->list, list->size, sizeof(list->list[0]), file_list_type_cmp);
|
qsort(list->list, list->size, sizeof(list->list[0]), file_list_type_cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *file_list_get_userdata_at_offset(const file_list_t *list, size_t idx)
|
void *file_list_get_userdata_at_offset(const file_list_t *list, size_t idx)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return NULL;
|
return NULL;
|
||||||
return list->list[idx].userdata;
|
return list->list[idx].userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_set_userdata(const file_list_t *list, size_t idx, void *ptr)
|
void file_list_set_userdata(const file_list_t *list, size_t idx, void *ptr)
|
||||||
{
|
{
|
||||||
if (!list || !ptr)
|
if (!list || !ptr)
|
||||||
return;
|
return;
|
||||||
list->list[idx].userdata = ptr;
|
list->list[idx].userdata = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_set_actiondata(const file_list_t *list, size_t idx, void *ptr)
|
void file_list_set_actiondata(const file_list_t *list, size_t idx, void *ptr)
|
||||||
{
|
{
|
||||||
if (!list || !ptr)
|
if (!list || !ptr)
|
||||||
return;
|
return;
|
||||||
list->list[idx].actiondata = ptr;
|
list->list[idx].actiondata = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *file_list_get_actiondata_at_offset(const file_list_t *list, size_t idx)
|
void *file_list_get_actiondata_at_offset(const file_list_t *list, size_t idx)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return NULL;
|
return NULL;
|
||||||
return list->list[idx].actiondata;
|
return list->list[idx].actiondata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_free_actiondata(const file_list_t *list, size_t idx)
|
void file_list_free_actiondata(const file_list_t *list, size_t idx)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
if (list->list[idx].actiondata)
|
if (list->list[idx].actiondata)
|
||||||
free(list->list[idx].actiondata);
|
free(list->list[idx].actiondata);
|
||||||
list->list[idx].actiondata = NULL;
|
list->list[idx].actiondata = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_free_userdata(const file_list_t *list, size_t idx)
|
void file_list_free_userdata(const file_list_t *list, size_t idx)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
if (list->list[idx].userdata)
|
if (list->list[idx].userdata)
|
||||||
free(list->list[idx].userdata);
|
free(list->list[idx].userdata);
|
||||||
list->list[idx].userdata = NULL;
|
list->list[idx].userdata = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *file_list_get_last_actiondata(const file_list_t *list)
|
void *file_list_get_last_actiondata(const file_list_t *list)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return NULL;
|
return NULL;
|
||||||
return list->list[list->size - 1].actiondata;
|
return list->list[list->size - 1].actiondata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_get_at_offset(const file_list_t *list, size_t idx,
|
void file_list_get_at_offset(const file_list_t *list, size_t idx,
|
||||||
const char **path, const char **label, unsigned *file_type,
|
const char **path, const char **label, unsigned *file_type,
|
||||||
size_t *entry_idx)
|
size_t *entry_idx)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (path)
|
if (path)
|
||||||
*path = list->list[idx].path;
|
*path = list->list[idx].path;
|
||||||
if (label)
|
if (label)
|
||||||
*label = list->list[idx].label;
|
*label = list->list[idx].label;
|
||||||
if (file_type)
|
if (file_type)
|
||||||
*file_type = list->list[idx].type;
|
*file_type = list->list[idx].type;
|
||||||
if (entry_idx)
|
if (entry_idx)
|
||||||
*entry_idx = list->list[idx].entry_idx;
|
*entry_idx = list->list[idx].entry_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_list_get_last(const file_list_t *list,
|
void file_list_get_last(const file_list_t *list,
|
||||||
const char **path, const char **label,
|
const char **path, const char **label,
|
||||||
unsigned *file_type, size_t *entry_idx)
|
unsigned *file_type, size_t *entry_idx)
|
||||||
{
|
{
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (list->size)
|
if (list->size)
|
||||||
file_list_get_at_offset(list, list->size - 1, path, label, file_type, entry_idx);
|
file_list_get_at_offset(list, list->size - 1, path, label, file_type, entry_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_list_search(const file_list_t *list, const char *needle, size_t *idx)
|
bool file_list_search(const file_list_t *list, const char *needle, size_t *idx)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
const char *alt;
|
const char *alt;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
file_list_get_alt_at_offset(list, i, &alt);
|
file_list_get_alt_at_offset(list, i, &alt);
|
||||||
if (!alt)
|
if (!alt)
|
||||||
{
|
{
|
||||||
file_list_get_label_at_offset(list, i, &alt);
|
file_list_get_label_at_offset(list, i, &alt);
|
||||||
if (!alt)
|
if (!alt)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = (const char *)strcasestr(alt, needle);
|
str = (const char *)strcasestr(alt, needle);
|
||||||
if (str == alt)
|
if (str == alt)
|
||||||
{
|
{
|
||||||
/* Found match with first chars, best possible match. */
|
/* Found match with first chars, best possible match. */
|
||||||
*idx = i;
|
*idx = i;
|
||||||
ret = true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (str && !ret)
|
else if (str && !ret)
|
||||||
{
|
{
|
||||||
/* Found mid-string match, but try to find a match with
|
/* Found mid-string match, but try to find a match with
|
||||||
* first characters before we settle. */
|
* first characters before we settle. */
|
||||||
*idx = i;
|
*idx = i;
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,275 +1,275 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (string_list.c).
|
* The following license statement only applies to this file (string_list.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <lists/string_list.h>
|
#include <lists/string_list.h>
|
||||||
#include <retro_assert.h>
|
#include <retro_assert.h>
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
#include <compat/posix_string.h>
|
#include <compat/posix_string.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_free
|
* string_list_free
|
||||||
* @list : pointer to string list object
|
* @list : pointer to string list object
|
||||||
*
|
*
|
||||||
* Frees a string list.
|
* Frees a string list.
|
||||||
*/
|
*/
|
||||||
void string_list_free(struct string_list *list)
|
void string_list_free(struct string_list *list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
free(list->elems[i].data);
|
free(list->elems[i].data);
|
||||||
free(list->elems);
|
free(list->elems);
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_capacity:
|
* string_list_capacity:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @cap : new capacity for string list.
|
* @cap : new capacity for string list.
|
||||||
*
|
*
|
||||||
* Change maximum capacity of string list's size.
|
* Change maximum capacity of string list's size.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if successful, otherwise false (0).
|
* Returns: true (1) if successful, otherwise false (0).
|
||||||
**/
|
**/
|
||||||
static bool string_list_capacity(struct string_list *list, size_t cap)
|
static bool string_list_capacity(struct string_list *list, size_t cap)
|
||||||
{
|
{
|
||||||
struct string_list_elem *new_data = NULL;
|
struct string_list_elem *new_data = NULL;
|
||||||
retro_assert(cap > list->size);
|
retro_assert(cap > list->size);
|
||||||
|
|
||||||
new_data = (struct string_list_elem*)
|
new_data = (struct string_list_elem*)
|
||||||
realloc(list->elems, cap * sizeof(*new_data));
|
realloc(list->elems, cap * sizeof(*new_data));
|
||||||
|
|
||||||
if (!new_data)
|
if (!new_data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (cap > list->cap)
|
if (cap > list->cap)
|
||||||
memset(&new_data[list->cap], 0, sizeof(*new_data) * (cap - list->cap));
|
memset(&new_data[list->cap], 0, sizeof(*new_data) * (cap - list->cap));
|
||||||
|
|
||||||
list->elems = new_data;
|
list->elems = new_data;
|
||||||
list->cap = cap;
|
list->cap = cap;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_new:
|
* string_list_new:
|
||||||
*
|
*
|
||||||
* Creates a new string list. Has to be freed manually.
|
* Creates a new string list. Has to be freed manually.
|
||||||
*
|
*
|
||||||
* Returns: new string list if successful, otherwise NULL.
|
* Returns: new string list if successful, otherwise NULL.
|
||||||
*/
|
*/
|
||||||
struct string_list *string_list_new(void)
|
struct string_list *string_list_new(void)
|
||||||
{
|
{
|
||||||
struct string_list *list = (struct string_list*)
|
struct string_list *list = (struct string_list*)
|
||||||
calloc(1, sizeof(*list));
|
calloc(1, sizeof(*list));
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!string_list_capacity(list, 32))
|
if (!string_list_capacity(list, 32))
|
||||||
{
|
{
|
||||||
string_list_free(list);
|
string_list_free(list);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_append:
|
* string_list_append:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @elem : element to add to the string list
|
* @elem : element to add to the string list
|
||||||
* @attr : attributes of new element.
|
* @attr : attributes of new element.
|
||||||
*
|
*
|
||||||
* Appends a new element to the string list.
|
* Appends a new element to the string list.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if successful, otherwise false (0).
|
* Returns: true (1) if successful, otherwise false (0).
|
||||||
**/
|
**/
|
||||||
bool string_list_append(struct string_list *list, const char *elem,
|
bool string_list_append(struct string_list *list, const char *elem,
|
||||||
union string_list_elem_attr attr)
|
union string_list_elem_attr attr)
|
||||||
{
|
{
|
||||||
char *data_dup = NULL;
|
char *data_dup = NULL;
|
||||||
|
|
||||||
if (list->size >= list->cap &&
|
if (list->size >= list->cap &&
|
||||||
!string_list_capacity(list, list->cap * 2))
|
!string_list_capacity(list, list->cap * 2))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
data_dup = strdup(elem);
|
data_dup = strdup(elem);
|
||||||
if (!data_dup)
|
if (!data_dup)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
list->elems[list->size].data = data_dup;
|
list->elems[list->size].data = data_dup;
|
||||||
list->elems[list->size].attr = attr;
|
list->elems[list->size].attr = attr;
|
||||||
|
|
||||||
list->size++;
|
list->size++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_set:
|
* string_list_set:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @idx : index of element in string list
|
* @idx : index of element in string list
|
||||||
* @str : value for the element.
|
* @str : value for the element.
|
||||||
*
|
*
|
||||||
* Set value of element inside string list.
|
* Set value of element inside string list.
|
||||||
**/
|
**/
|
||||||
void string_list_set(struct string_list *list,
|
void string_list_set(struct string_list *list,
|
||||||
unsigned idx, const char *str)
|
unsigned idx, const char *str)
|
||||||
{
|
{
|
||||||
free(list->elems[idx].data);
|
free(list->elems[idx].data);
|
||||||
retro_assert(list->elems[idx].data = strdup(str));
|
retro_assert(list->elems[idx].data = strdup(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_join_concat:
|
* string_list_join_concat:
|
||||||
* @buffer : buffer that @list will be joined to.
|
* @buffer : buffer that @list will be joined to.
|
||||||
* @size : length of @buffer.
|
* @size : length of @buffer.
|
||||||
* @list : pointer to string list.
|
* @list : pointer to string list.
|
||||||
* @delim : delimiter character for @list.
|
* @delim : delimiter character for @list.
|
||||||
*
|
*
|
||||||
* A string list will be joined/concatenated as a
|
* A string list will be joined/concatenated as a
|
||||||
* string to @buffer, delimited by @delim.
|
* string to @buffer, delimited by @delim.
|
||||||
*/
|
*/
|
||||||
void string_list_join_concat(char *buffer, size_t size,
|
void string_list_join_concat(char *buffer, size_t size,
|
||||||
const struct string_list *list, const char *delim)
|
const struct string_list *list, const char *delim)
|
||||||
{
|
{
|
||||||
size_t i, len = strlen(buffer);
|
size_t i, len = strlen(buffer);
|
||||||
|
|
||||||
retro_assert(len < size);
|
retro_assert(len < size);
|
||||||
buffer += len;
|
buffer += len;
|
||||||
size -= len;
|
size -= len;
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
strlcat(buffer, list->elems[i].data, size);
|
strlcat(buffer, list->elems[i].data, size);
|
||||||
if ((i + 1) < list->size)
|
if ((i + 1) < list->size)
|
||||||
strlcat(buffer, delim, size);
|
strlcat(buffer, delim, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_split:
|
* string_split:
|
||||||
* @str : string to turn into a string list
|
* @str : string to turn into a string list
|
||||||
* @delim : delimiter character to use for splitting the string.
|
* @delim : delimiter character to use for splitting the string.
|
||||||
*
|
*
|
||||||
* Creates a new string list based on string @str, delimited by @delim.
|
* Creates a new string list based on string @str, delimited by @delim.
|
||||||
*
|
*
|
||||||
* Returns: new string list if successful, otherwise NULL.
|
* Returns: new string list if successful, otherwise NULL.
|
||||||
*/
|
*/
|
||||||
struct string_list *string_split(const char *str, const char *delim)
|
struct string_list *string_split(const char *str, const char *delim)
|
||||||
{
|
{
|
||||||
char *save = NULL;
|
char *save = NULL;
|
||||||
char *copy = NULL;
|
char *copy = NULL;
|
||||||
const char *tmp = NULL;
|
const char *tmp = NULL;
|
||||||
struct string_list *list = string_list_new();
|
struct string_list *list = string_list_new();
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
copy = strdup(str);
|
copy = strdup(str);
|
||||||
if (!copy)
|
if (!copy)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
tmp = strtok_r(copy, delim, &save);
|
tmp = strtok_r(copy, delim, &save);
|
||||||
while (tmp)
|
while (tmp)
|
||||||
{
|
{
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
memset(&attr, 0, sizeof(attr));
|
memset(&attr, 0, sizeof(attr));
|
||||||
|
|
||||||
if (!string_list_append(list, tmp, attr))
|
if (!string_list_append(list, tmp, attr))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
tmp = strtok_r(NULL, delim, &save);
|
tmp = strtok_r(NULL, delim, &save);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(copy);
|
free(copy);
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
string_list_free(list);
|
string_list_free(list);
|
||||||
free(copy);
|
free(copy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_find_elem:
|
* string_list_find_elem:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @elem : element to find inside the string list.
|
* @elem : element to find inside the string list.
|
||||||
*
|
*
|
||||||
* Searches for an element (@elem) inside the string list.
|
* Searches for an element (@elem) inside the string list.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if element could be found, otherwise false (0).
|
* Returns: true (1) if element could be found, otherwise false (0).
|
||||||
*/
|
*/
|
||||||
int string_list_find_elem(const struct string_list *list, const char *elem)
|
int string_list_find_elem(const struct string_list *list, const char *elem)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
if (strcasecmp(list->elems[i].data, elem) == 0)
|
if (strcasecmp(list->elems[i].data, elem) == 0)
|
||||||
return i+1;
|
return i+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_find_elem_prefix:
|
* string_list_find_elem_prefix:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
* @prefix : prefix to append to @elem
|
* @prefix : prefix to append to @elem
|
||||||
* @elem : element to find inside the string list.
|
* @elem : element to find inside the string list.
|
||||||
*
|
*
|
||||||
* Searches for an element (@elem) inside the string list. Will
|
* Searches for an element (@elem) inside the string list. Will
|
||||||
* also search for the same element prefixed by @prefix.
|
* also search for the same element prefixed by @prefix.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if element could be found, otherwise false (0).
|
* Returns: true (1) if element could be found, otherwise false (0).
|
||||||
*/
|
*/
|
||||||
bool string_list_find_elem_prefix(const struct string_list *list,
|
bool string_list_find_elem_prefix(const struct string_list *list,
|
||||||
const char *prefix, const char *elem)
|
const char *prefix, const char *elem)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char prefixed[PATH_MAX_LENGTH] = {0};
|
char prefixed[PATH_MAX_LENGTH] = {0};
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
strlcpy(prefixed, prefix, sizeof(prefixed));
|
strlcpy(prefixed, prefix, sizeof(prefixed));
|
||||||
strlcat(prefixed, elem, sizeof(prefixed));
|
strlcat(prefixed, elem, sizeof(prefixed));
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
if (strcasecmp(list->elems[i].data, elem) == 0 ||
|
if (strcasecmp(list->elems[i].data, elem) == 0 ||
|
||||||
strcasecmp(list->elems[i].data, prefixed) == 0)
|
strcasecmp(list->elems[i].data, prefixed) == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,178 +1,178 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (compat_fnmatch.c).
|
* The following license statement only applies to this file (compat_fnmatch.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(_XBOX)
|
#if defined(_WIN32) && !defined(_XBOX)
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <IPHlpApi.h>
|
#include <IPHlpApi.h>
|
||||||
#include <WS2tcpip.h>
|
#include <WS2tcpip.h>
|
||||||
#else
|
#else
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#ifdef WANT_IFADDRS
|
#ifdef WANT_IFADDRS
|
||||||
#include <compat/ifaddrs.h>
|
#include <compat/ifaddrs.h>
|
||||||
#else
|
#else
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <net/net_ifinfo.h>
|
#include <net/net_ifinfo.h>
|
||||||
|
|
||||||
void net_ifinfo_free(net_ifinfo_t *list)
|
void net_ifinfo_free(net_ifinfo_t *list)
|
||||||
{
|
{
|
||||||
unsigned k;
|
unsigned k;
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (k = 0; k < list->size; k++)
|
for (k = 0; k < list->size; k++)
|
||||||
{
|
{
|
||||||
struct net_ifinfo_entry *ptr =
|
struct net_ifinfo_entry *ptr =
|
||||||
(struct net_ifinfo_entry*)&list->entries[k];
|
(struct net_ifinfo_entry*)&list->entries[k];
|
||||||
|
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (*ptr->name)
|
if (*ptr->name)
|
||||||
free(ptr->name);
|
free(ptr->name);
|
||||||
if (*ptr->host)
|
if (*ptr->host)
|
||||||
free(ptr->host);
|
free(ptr->host);
|
||||||
|
|
||||||
ptr->name = NULL;
|
ptr->name = NULL;
|
||||||
ptr->host = NULL;
|
ptr->host = NULL;
|
||||||
}
|
}
|
||||||
free(list->entries);
|
free(list->entries);
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool net_ifinfo_new(net_ifinfo_t *list)
|
bool net_ifinfo_new(net_ifinfo_t *list)
|
||||||
{
|
{
|
||||||
unsigned k = 0;
|
unsigned k = 0;
|
||||||
#if defined(_WIN32) && !defined(_XBOX)
|
#if defined(_WIN32) && !defined(_XBOX)
|
||||||
DWORD size;
|
DWORD size;
|
||||||
PIP_ADAPTER_ADDRESSES adapter_addresses, aa;
|
PIP_ADAPTER_ADDRESSES adapter_addresses, aa;
|
||||||
PIP_ADAPTER_UNICAST_ADDRESS ua;
|
PIP_ADAPTER_UNICAST_ADDRESS ua;
|
||||||
|
|
||||||
DWORD rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, NULL, &size);
|
DWORD rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, NULL, &size);
|
||||||
|
|
||||||
adapter_addresses = (PIP_ADAPTER_ADDRESSES)malloc(size);
|
adapter_addresses = (PIP_ADAPTER_ADDRESSES)malloc(size);
|
||||||
|
|
||||||
rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, adapter_addresses, &size);
|
rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, adapter_addresses, &size);
|
||||||
|
|
||||||
if (rv != ERROR_SUCCESS)
|
if (rv != ERROR_SUCCESS)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
for (aa = adapter_addresses; aa != NULL; aa = aa->Next)
|
for (aa = adapter_addresses; aa != NULL; aa = aa->Next)
|
||||||
{
|
{
|
||||||
char name[PATH_MAX_LENGTH];
|
char name[PATH_MAX_LENGTH];
|
||||||
memset(name, 0, sizeof(name));
|
memset(name, 0, sizeof(name));
|
||||||
|
|
||||||
WideCharToMultiByte(CP_ACP, 0, aa->FriendlyName, wcslen(aa->FriendlyName),
|
WideCharToMultiByte(CP_ACP, 0, aa->FriendlyName, wcslen(aa->FriendlyName),
|
||||||
name, PATH_MAX_LENGTH, NULL, NULL);
|
name, PATH_MAX_LENGTH, NULL, NULL);
|
||||||
|
|
||||||
for (ua = aa->FirstUnicastAddress; ua != NULL; ua = ua->Next)
|
for (ua = aa->FirstUnicastAddress; ua != NULL; ua = ua->Next)
|
||||||
{
|
{
|
||||||
char host[PATH_MAX_LENGTH];
|
char host[PATH_MAX_LENGTH];
|
||||||
struct net_ifinfo_entry *ptr = (struct net_ifinfo_entry*)
|
struct net_ifinfo_entry *ptr = (struct net_ifinfo_entry*)
|
||||||
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
|
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
|
||||||
|
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
list->entries = ptr;
|
list->entries = ptr;
|
||||||
|
|
||||||
memset(host, 0, sizeof(host));
|
memset(host, 0, sizeof(host));
|
||||||
|
|
||||||
getnameinfo(ua->Address.lpSockaddr, ua->Address.iSockaddrLength,
|
getnameinfo(ua->Address.lpSockaddr, ua->Address.iSockaddrLength,
|
||||||
host, sizeof(host), NULL, NI_MAXSERV, NI_NUMERICHOST);
|
host, sizeof(host), NULL, NI_MAXSERV, NI_NUMERICHOST);
|
||||||
|
|
||||||
list->entries[k].name = strdup(name);
|
list->entries[k].name = strdup(name);
|
||||||
list->entries[k].host = strdup(host);
|
list->entries[k].host = strdup(host);
|
||||||
list->size = k + 1;
|
list->size = k + 1;
|
||||||
|
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(adapter_addresses);
|
free(adapter_addresses);
|
||||||
#else
|
#else
|
||||||
struct ifaddrs *ifa = NULL;
|
struct ifaddrs *ifa = NULL;
|
||||||
struct ifaddrs *ifaddr = NULL;
|
struct ifaddrs *ifaddr = NULL;
|
||||||
|
|
||||||
if (getifaddrs(&ifaddr) == -1)
|
if (getifaddrs(&ifaddr) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
|
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
|
||||||
{
|
{
|
||||||
char host[NI_MAXHOST];
|
char host[NI_MAXHOST];
|
||||||
struct net_ifinfo_entry *ptr = NULL;
|
struct net_ifinfo_entry *ptr = NULL;
|
||||||
|
|
||||||
if (!ifa->ifa_addr)
|
if (!ifa->ifa_addr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ifa->ifa_addr->sa_family != AF_INET)
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
|
if (getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
|
||||||
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0)
|
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ptr = (struct net_ifinfo_entry*)
|
ptr = (struct net_ifinfo_entry*)
|
||||||
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
|
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
|
||||||
|
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
list->entries = ptr;
|
list->entries = ptr;
|
||||||
|
|
||||||
list->entries[k].name = strdup(ifa->ifa_name);
|
list->entries[k].name = strdup(ifa->ifa_name);
|
||||||
list->entries[k].host = strdup(host);
|
list->entries[k].host = strdup(host);
|
||||||
list->size = k + 1;
|
list->size = k + 1;
|
||||||
|
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeifaddrs(ifaddr);
|
freeifaddrs(ifaddr);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (adapter_addresses)
|
if (adapter_addresses)
|
||||||
free(adapter_addresses);
|
free(adapter_addresses);
|
||||||
#else
|
#else
|
||||||
freeifaddrs(ifaddr);
|
freeifaddrs(ifaddr);
|
||||||
#endif
|
#endif
|
||||||
net_ifinfo_free(list);
|
net_ifinfo_free(list);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +1,49 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (compat_fnmatch.c).
|
* The following license statement only applies to this file (compat_fnmatch.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <net/net_ifinfo.h>
|
#include <net/net_ifinfo.h>
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
unsigned k = 0;
|
unsigned k = 0;
|
||||||
net_ifinfo_t *list =
|
net_ifinfo_t *list =
|
||||||
(net_ifinfo_t*)calloc(1, sizeof(*list));
|
(net_ifinfo_t*)calloc(1, sizeof(*list));
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!net_ifinfo_new(list))
|
if (!net_ifinfo_new(list))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (k = 0; k < list->size; k++)
|
for (k = 0; k < list->size; k++)
|
||||||
{
|
{
|
||||||
printf("%s:%s\n", list->entries[k].name, list->entries[k].host);
|
printf("%s:%s\n", list->entries[k].name, list->entries[k].host);
|
||||||
}
|
}
|
||||||
|
|
||||||
net_ifinfo_free(list);
|
net_ifinfo_free(list);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,124 +1,124 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (fifo_queue.c).
|
* The following license statement only applies to this file (fifo_queue.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <queues/fifo_queue.h>
|
#include <queues/fifo_queue.h>
|
||||||
|
|
||||||
struct fifo_buffer
|
struct fifo_buffer
|
||||||
{
|
{
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t first;
|
size_t first;
|
||||||
size_t end;
|
size_t end;
|
||||||
};
|
};
|
||||||
|
|
||||||
fifo_buffer_t *fifo_new(size_t size)
|
fifo_buffer_t *fifo_new(size_t size)
|
||||||
{
|
{
|
||||||
fifo_buffer_t *buf = (fifo_buffer_t*)calloc(1, sizeof(*buf));
|
fifo_buffer_t *buf = (fifo_buffer_t*)calloc(1, sizeof(*buf));
|
||||||
|
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
buf->buffer = (uint8_t*)calloc(1, size + 1);
|
buf->buffer = (uint8_t*)calloc(1, size + 1);
|
||||||
if (!buf->buffer)
|
if (!buf->buffer)
|
||||||
{
|
{
|
||||||
free(buf);
|
free(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
buf->size = size + 1;
|
buf->size = size + 1;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fifo_clear(fifo_buffer_t *buffer)
|
void fifo_clear(fifo_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
buffer->first = 0;
|
buffer->first = 0;
|
||||||
buffer->end = 0;
|
buffer->end = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fifo_free(fifo_buffer_t *buffer)
|
void fifo_free(fifo_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
free(buffer->buffer);
|
free(buffer->buffer);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fifo_read_avail(fifo_buffer_t *buffer)
|
size_t fifo_read_avail(fifo_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
size_t first = buffer->first;
|
size_t first = buffer->first;
|
||||||
size_t end = buffer->end;
|
size_t end = buffer->end;
|
||||||
|
|
||||||
if (end < first)
|
if (end < first)
|
||||||
end += buffer->size;
|
end += buffer->size;
|
||||||
return end - first;
|
return end - first;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fifo_write_avail(fifo_buffer_t *buffer)
|
size_t fifo_write_avail(fifo_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
size_t first = buffer->first;
|
size_t first = buffer->first;
|
||||||
size_t end = buffer->end;
|
size_t end = buffer->end;
|
||||||
|
|
||||||
if (end < first)
|
if (end < first)
|
||||||
end += buffer->size;
|
end += buffer->size;
|
||||||
|
|
||||||
return (buffer->size - 1) - (end - first);
|
return (buffer->size - 1) - (end - first);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size)
|
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size)
|
||||||
{
|
{
|
||||||
size_t first_write = size;
|
size_t first_write = size;
|
||||||
size_t rest_write = 0;
|
size_t rest_write = 0;
|
||||||
|
|
||||||
if (buffer->end + size > buffer->size)
|
if (buffer->end + size > buffer->size)
|
||||||
{
|
{
|
||||||
first_write = buffer->size - buffer->end;
|
first_write = buffer->size - buffer->end;
|
||||||
rest_write = size - first_write;
|
rest_write = size - first_write;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buffer->buffer + buffer->end, in_buf, first_write);
|
memcpy(buffer->buffer + buffer->end, in_buf, first_write);
|
||||||
memcpy(buffer->buffer, (const uint8_t*)in_buf + first_write, rest_write);
|
memcpy(buffer->buffer, (const uint8_t*)in_buf + first_write, rest_write);
|
||||||
|
|
||||||
buffer->end = (buffer->end + size) % buffer->size;
|
buffer->end = (buffer->end + size) % buffer->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size)
|
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size)
|
||||||
{
|
{
|
||||||
size_t first_read = size;
|
size_t first_read = size;
|
||||||
size_t rest_read = 0;
|
size_t rest_read = 0;
|
||||||
|
|
||||||
if (buffer->first + size > buffer->size)
|
if (buffer->first + size > buffer->size)
|
||||||
{
|
{
|
||||||
first_read = buffer->size - buffer->first;
|
first_read = buffer->size - buffer->first;
|
||||||
rest_read = size - first_read;
|
rest_read = size - first_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(in_buf, (const uint8_t*)buffer->buffer + buffer->first, first_read);
|
memcpy(in_buf, (const uint8_t*)buffer->buffer + buffer->first, first_read);
|
||||||
memcpy((uint8_t*)in_buf + first_read, buffer->buffer, rest_read);
|
memcpy((uint8_t*)in_buf + first_read, buffer->buffer, rest_read);
|
||||||
|
|
||||||
buffer->first = (buffer->first + size) % buffer->size;
|
buffer->first = (buffer->first + size) % buffer->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,142 +1,142 @@
|
||||||
/* Copyright (C) 2010-2016 The RetroArch team
|
/* Copyright (C) 2010-2016 The RetroArch team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (memory_stream.c).
|
* The following license statement only applies to this file (memory_stream.c).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* 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
|
* 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,
|
* 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:
|
* 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 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,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* 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,
|
* 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,
|
* 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.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <streams/memory_stream.h>
|
#include <streams/memory_stream.h>
|
||||||
|
|
||||||
static uint8_t* g_buffer = NULL;
|
static uint8_t* g_buffer = NULL;
|
||||||
static size_t g_size = 0;
|
static size_t g_size = 0;
|
||||||
static size_t last_file_size = 0;
|
static size_t last_file_size = 0;
|
||||||
|
|
||||||
struct memstream
|
struct memstream
|
||||||
{
|
{
|
||||||
uint8_t *m_buf;
|
uint8_t *m_buf;
|
||||||
size_t m_size;
|
size_t m_size;
|
||||||
size_t m_ptr;
|
size_t m_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void memstream_set_buffer(uint8_t *buffer, size_t size)
|
void memstream_set_buffer(uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
g_buffer = buffer;
|
g_buffer = buffer;
|
||||||
g_size = size;
|
g_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memstream_get_last_size(void)
|
size_t memstream_get_last_size(void)
|
||||||
{
|
{
|
||||||
return last_file_size;
|
return last_file_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void memstream_init(memstream_t *stream, uint8_t *buffer, size_t max_size)
|
static void memstream_init(memstream_t *stream, uint8_t *buffer, size_t max_size)
|
||||||
{
|
{
|
||||||
stream->m_buf = buffer;
|
stream->m_buf = buffer;
|
||||||
stream->m_size = max_size;
|
stream->m_size = max_size;
|
||||||
stream->m_ptr = 0;
|
stream->m_ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memstream_t *memstream_open(void)
|
memstream_t *memstream_open(void)
|
||||||
{
|
{
|
||||||
memstream_t *stream;
|
memstream_t *stream;
|
||||||
if (!g_buffer || !g_size)
|
if (!g_buffer || !g_size)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
stream = (memstream_t*)calloc(1, sizeof(*stream));
|
stream = (memstream_t*)calloc(1, sizeof(*stream));
|
||||||
memstream_init(stream, g_buffer, g_size);
|
memstream_init(stream, g_buffer, g_size);
|
||||||
|
|
||||||
g_buffer = NULL;
|
g_buffer = NULL;
|
||||||
g_size = 0;
|
g_size = 0;
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memstream_close(memstream_t *stream)
|
void memstream_close(memstream_t *stream)
|
||||||
{
|
{
|
||||||
last_file_size = stream->m_ptr;
|
last_file_size = stream->m_ptr;
|
||||||
free(stream);
|
free(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memstream_read(memstream_t *stream, void *data, size_t bytes)
|
size_t memstream_read(memstream_t *stream, void *data, size_t bytes)
|
||||||
{
|
{
|
||||||
size_t avail = stream->m_size - stream->m_ptr;
|
size_t avail = stream->m_size - stream->m_ptr;
|
||||||
if (bytes > avail)
|
if (bytes > avail)
|
||||||
bytes = avail;
|
bytes = avail;
|
||||||
|
|
||||||
memcpy(data, stream->m_buf + stream->m_ptr, bytes);
|
memcpy(data, stream->m_buf + stream->m_ptr, bytes);
|
||||||
stream->m_ptr += bytes;
|
stream->m_ptr += bytes;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memstream_write(memstream_t *stream, const void *data, size_t bytes)
|
size_t memstream_write(memstream_t *stream, const void *data, size_t bytes)
|
||||||
{
|
{
|
||||||
size_t avail = stream->m_size - stream->m_ptr;
|
size_t avail = stream->m_size - stream->m_ptr;
|
||||||
if (bytes > avail)
|
if (bytes > avail)
|
||||||
bytes = avail;
|
bytes = avail;
|
||||||
|
|
||||||
memcpy(stream->m_buf + stream->m_ptr, data, bytes);
|
memcpy(stream->m_buf + stream->m_ptr, data, bytes);
|
||||||
stream->m_ptr += bytes;
|
stream->m_ptr += bytes;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int memstream_seek(memstream_t *stream, int offset, int whence)
|
int memstream_seek(memstream_t *stream, int offset, int whence)
|
||||||
{
|
{
|
||||||
size_t ptr;
|
size_t ptr;
|
||||||
|
|
||||||
switch (whence)
|
switch (whence)
|
||||||
{
|
{
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
ptr = offset;
|
ptr = offset;
|
||||||
break;
|
break;
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
ptr = stream->m_ptr + offset;
|
ptr = stream->m_ptr + offset;
|
||||||
break;
|
break;
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
ptr = stream->m_size + offset;
|
ptr = stream->m_size + offset;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr <= stream->m_size)
|
if (ptr <= stream->m_size)
|
||||||
{
|
{
|
||||||
stream->m_ptr = ptr;
|
stream->m_ptr = ptr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memstream_pos(memstream_t *stream)
|
size_t memstream_pos(memstream_t *stream)
|
||||||
{
|
{
|
||||||
return stream->m_ptr;
|
return stream->m_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *memstream_gets(memstream_t *stream, char *buffer, size_t len)
|
char *memstream_gets(memstream_t *stream, char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int memstream_getc(memstream_t *stream)
|
int memstream_getc(memstream_t *stream)
|
||||||
{
|
{
|
||||||
if (stream->m_ptr >= stream->m_size)
|
if (stream->m_ptr >= stream->m_size)
|
||||||
return EOF;
|
return EOF;
|
||||||
return stream->m_buf[stream->m_ptr++];
|
return stream->m_buf[stream->m_ptr++];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue