remove a bunch of eol-style properties... again.. bear with me.

This commit is contained in:
zeromus 2016-03-21 02:15:01 +00:00
parent 7f0c1276d4
commit a0e0aed5a4
20 changed files with 4270 additions and 4270 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,213 +1,213 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (archive_file_zlib.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <compat/zlib.h>
#include <file/archive_file.h>
#include <streams/file_stream.h>
static void *zlib_stream_new(void)
{
return (z_stream*)calloc(1, sizeof(z_stream));
}
static void zlib_stream_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
inflateEnd(ret);
}
static void zlib_stream_set(void *data,
uint32_t avail_in,
uint32_t avail_out,
const uint8_t *next_in,
uint8_t *next_out
)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return;
stream->avail_in = avail_in;
stream->avail_out = avail_out;
stream->next_in = (uint8_t*)next_in;
stream->next_out = next_out;
}
static uint32_t zlib_stream_get_avail_in(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return 0;
return stream->avail_in;
}
static uint32_t zlib_stream_get_avail_out(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return 0;
return stream->avail_out;
}
static uint64_t zlib_stream_get_total_out(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return 0;
return stream->total_out;
}
static void zlib_stream_decrement_total_out(void *data, unsigned subtraction)
{
z_stream *stream = (z_stream*)data;
if (stream)
stream->total_out -= subtraction;
}
static void zlib_stream_compress_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
deflateEnd(ret);
}
static int zlib_stream_compress_data_to_file(void *data)
{
int zstatus;
z_stream *stream = (z_stream*)data;
if (!stream)
return -1;
zstatus = deflate(stream, Z_FINISH);
if (zstatus == Z_STREAM_END)
return 1;
return 0;
}
static bool zlib_stream_decompress_init(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return false;
if (inflateInit(stream) != Z_OK)
return false;
return true;
}
static bool zlib_stream_decompress_data_to_file_init(
file_archive_file_handle_t *handle,
const uint8_t *cdata, uint32_t csize, uint32_t size)
{
if (!handle)
return false;
if (!(handle->stream = (z_stream*)zlib_stream_new()))
goto error;
if (inflateInit2((z_streamp)handle->stream, -MAX_WBITS) != Z_OK)
goto error;
handle->data = (uint8_t*)malloc(size);
if (!handle->data)
goto error;
zlib_stream_set(handle->stream, csize, size,
(const uint8_t*)cdata, handle->data);
return true;
error:
zlib_stream_free(handle->stream);
free(handle->stream);
if (handle->data)
free(handle->data);
return false;
}
static int zlib_stream_decompress_data_to_file_iterate(void *data)
{
int zstatus;
z_stream *stream = (z_stream*)data;
if (!stream)
return -1;
zstatus = inflate(stream, Z_NO_FLUSH);
if (zstatus == Z_STREAM_END)
return 1;
if (zstatus != Z_OK && zstatus != Z_BUF_ERROR)
return -1;
return 0;
}
static void zlib_stream_compress_init(void *data, int level)
{
z_stream *stream = (z_stream*)data;
if (stream)
deflateInit(stream, level);
}
static uint32_t zlib_stream_crc32_calculate(uint32_t crc,
const uint8_t *data, size_t length)
{
return crc32(crc, data, length);
}
const struct file_archive_file_backend zlib_backend = {
zlib_stream_new,
zlib_stream_free,
zlib_stream_set,
zlib_stream_get_avail_in,
zlib_stream_get_avail_out,
zlib_stream_get_total_out,
zlib_stream_decrement_total_out,
zlib_stream_decompress_init,
zlib_stream_decompress_data_to_file_init,
zlib_stream_decompress_data_to_file_iterate,
zlib_stream_compress_init,
zlib_stream_compress_free,
zlib_stream_compress_data_to_file,
zlib_stream_crc32_calculate,
"zlib"
};
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (archive_file_zlib.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <compat/zlib.h>
#include <file/archive_file.h>
#include <streams/file_stream.h>
static void *zlib_stream_new(void)
{
return (z_stream*)calloc(1, sizeof(z_stream));
}
static void zlib_stream_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
inflateEnd(ret);
}
static void zlib_stream_set(void *data,
uint32_t avail_in,
uint32_t avail_out,
const uint8_t *next_in,
uint8_t *next_out
)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return;
stream->avail_in = avail_in;
stream->avail_out = avail_out;
stream->next_in = (uint8_t*)next_in;
stream->next_out = next_out;
}
static uint32_t zlib_stream_get_avail_in(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return 0;
return stream->avail_in;
}
static uint32_t zlib_stream_get_avail_out(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return 0;
return stream->avail_out;
}
static uint64_t zlib_stream_get_total_out(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return 0;
return stream->total_out;
}
static void zlib_stream_decrement_total_out(void *data, unsigned subtraction)
{
z_stream *stream = (z_stream*)data;
if (stream)
stream->total_out -= subtraction;
}
static void zlib_stream_compress_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
deflateEnd(ret);
}
static int zlib_stream_compress_data_to_file(void *data)
{
int zstatus;
z_stream *stream = (z_stream*)data;
if (!stream)
return -1;
zstatus = deflate(stream, Z_FINISH);
if (zstatus == Z_STREAM_END)
return 1;
return 0;
}
static bool zlib_stream_decompress_init(void *data)
{
z_stream *stream = (z_stream*)data;
if (!stream)
return false;
if (inflateInit(stream) != Z_OK)
return false;
return true;
}
static bool zlib_stream_decompress_data_to_file_init(
file_archive_file_handle_t *handle,
const uint8_t *cdata, uint32_t csize, uint32_t size)
{
if (!handle)
return false;
if (!(handle->stream = (z_stream*)zlib_stream_new()))
goto error;
if (inflateInit2((z_streamp)handle->stream, -MAX_WBITS) != Z_OK)
goto error;
handle->data = (uint8_t*)malloc(size);
if (!handle->data)
goto error;
zlib_stream_set(handle->stream, csize, size,
(const uint8_t*)cdata, handle->data);
return true;
error:
zlib_stream_free(handle->stream);
free(handle->stream);
if (handle->data)
free(handle->data);
return false;
}
static int zlib_stream_decompress_data_to_file_iterate(void *data)
{
int zstatus;
z_stream *stream = (z_stream*)data;
if (!stream)
return -1;
zstatus = inflate(stream, Z_NO_FLUSH);
if (zstatus == Z_STREAM_END)
return 1;
if (zstatus != Z_OK && zstatus != Z_BUF_ERROR)
return -1;
return 0;
}
static void zlib_stream_compress_init(void *data, int level)
{
z_stream *stream = (z_stream*)data;
if (stream)
deflateInit(stream, level);
}
static uint32_t zlib_stream_crc32_calculate(uint32_t crc,
const uint8_t *data, size_t length)
{
return crc32(crc, data, length);
}
const struct file_archive_file_backend zlib_backend = {
zlib_stream_new,
zlib_stream_free,
zlib_stream_set,
zlib_stream_get_avail_in,
zlib_stream_get_avail_out,
zlib_stream_get_total_out,
zlib_stream_decrement_total_out,
zlib_stream_decompress_init,
zlib_stream_decompress_data_to_file_init,
zlib_stream_decompress_data_to_file_iterate,
zlib_stream_compress_init,
zlib_stream_compress_free,
zlib_stream_compress_data_to_file,
zlib_stream_crc32_calculate,
"zlib"
};

View File

@ -1,53 +1,53 @@
/*
* Copyright (c) 1995, 1999
* Berkeley Software Design, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* 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
* SUCH DAMAGE.
*
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
*/
#ifndef _IFADDRS_H_
#define _IFADDRS_H_
struct ifaddrs
{
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
struct sockaddr *ifa_dstaddr;
void *ifa_data;
};
/*
* 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.
*/
#ifndef ifa_broadaddr
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
#endif
#include <sys/cdefs.h>
extern int getifaddrs(struct ifaddrs **ifap);
extern void freeifaddrs(struct ifaddrs *ifa);
#endif
/*
* Copyright (c) 1995, 1999
* Berkeley Software Design, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* 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
* SUCH DAMAGE.
*
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
*/
#ifndef _IFADDRS_H_
#define _IFADDRS_H_
struct ifaddrs
{
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
struct sockaddr *ifa_dstaddr;
void *ifa_data;
};
/*
* 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.
*/
#ifndef ifa_broadaddr
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
#endif
#include <sys/cdefs.h>
extern int getifaddrs(struct ifaddrs **ifap);
extern void freeifaddrs(struct ifaddrs *ifa);
#endif

View File

@ -1,138 +1,138 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (archive_file.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LIBRETRO_SDK_ARCHIVE_FILE_H__
#define LIBRETRO_SDK_ARCHIVE_FILE_H__
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
enum file_archive_transfer_type
{
ZLIB_TRANSFER_NONE = 0,
ZLIB_TRANSFER_INIT,
ZLIB_TRANSFER_ITERATE,
ZLIB_TRANSFER_DEINIT,
ZLIB_TRANSFER_DEINIT_ERROR
};
typedef struct file_archive_handle
{
void *stream;
uint8_t *data;
uint32_t real_checksum;
const struct file_archive_file_backend *backend;
} file_archive_file_handle_t;
struct file_archive_file_backend
{
void *(*stream_new)(void);
void (*stream_free)(void *);
void (*stream_set)(void *, uint32_t, uint32_t,
const uint8_t *, uint8_t *);
uint32_t (*stream_get_avail_in)(void*);
uint32_t (*stream_get_avail_out)(void*);
uint64_t (*stream_get_total_out)(void*);
void (*stream_decrement_total_out)(void *, unsigned);
bool (*stream_decompress_init)(void *);
bool (*stream_decompress_data_to_file_init)(
file_archive_file_handle_t *, const uint8_t *, uint32_t, uint32_t);
int (*stream_decompress_data_to_file_iterate)(void *);
void (*stream_compress_init)(void *, int);
void (*stream_compress_free)(void *);
int (*stream_compress_data_to_file)(void *);
uint32_t (*stream_crc_calculate)(uint32_t, const uint8_t *, size_t);
const char *ident;
};
typedef struct file_archive_transfer
{
void *handle;
const uint8_t *footer;
const uint8_t *directory;
const uint8_t *data;
int32_t zip_size;
enum file_archive_transfer_type type;
const struct file_archive_file_backend *backend;
} file_archive_transfer_t;
/* Returns true when parsing should continue. False to stop. */
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,
uint32_t crc32, void *userdata);
int file_archive_parse_file_iterate(
file_archive_transfer_t *state,
bool *returnerr,
const char *file,
const char *valid_exts,
file_archive_file_cb file_cb,
void *userdata);
void file_archive_parse_file_iterate_stop(file_archive_transfer_t *state);
int file_archive_parse_file_progress(file_archive_transfer_t *state);
/**
* file_archive_extract_first_content_file:
* @zip_path : filename path to ZIP archive.
* @zip_path_size : size of ZIP archive.
* @valid_exts : valid extensions for a content file.
* @extraction_directory : the directory to extract temporary
* unzipped content to.
*
* Extract first content file from archive.
*
* Returns : true (1) on success, otherwise false (0).
**/
bool file_archive_extract_first_content_file(char *zip_path, size_t zip_path_size,
const char *valid_exts, const char *extraction_dir,
char *out_path, size_t len);
/**
* file_archive_get_file_list:
* @path : filename path of archive
* @valid_exts : Valid extensions of archive to be parsed.
* If NULL, allow all.
*
* 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);
bool file_archive_perform_mode(const char *name, const char *valid_exts,
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
uint32_t crc32, void *userdata);
struct string_list *compressed_file_list_new(const char *filename,
const char* ext);
void file_archive_deflate_init(void *data, int level);
const struct file_archive_file_backend *file_archive_get_default_file_backend(void);
extern const struct file_archive_file_backend zlib_backend;
#endif
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (archive_file.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LIBRETRO_SDK_ARCHIVE_FILE_H__
#define LIBRETRO_SDK_ARCHIVE_FILE_H__
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
enum file_archive_transfer_type
{
ZLIB_TRANSFER_NONE = 0,
ZLIB_TRANSFER_INIT,
ZLIB_TRANSFER_ITERATE,
ZLIB_TRANSFER_DEINIT,
ZLIB_TRANSFER_DEINIT_ERROR
};
typedef struct file_archive_handle
{
void *stream;
uint8_t *data;
uint32_t real_checksum;
const struct file_archive_file_backend *backend;
} file_archive_file_handle_t;
struct file_archive_file_backend
{
void *(*stream_new)(void);
void (*stream_free)(void *);
void (*stream_set)(void *, uint32_t, uint32_t,
const uint8_t *, uint8_t *);
uint32_t (*stream_get_avail_in)(void*);
uint32_t (*stream_get_avail_out)(void*);
uint64_t (*stream_get_total_out)(void*);
void (*stream_decrement_total_out)(void *, unsigned);
bool (*stream_decompress_init)(void *);
bool (*stream_decompress_data_to_file_init)(
file_archive_file_handle_t *, const uint8_t *, uint32_t, uint32_t);
int (*stream_decompress_data_to_file_iterate)(void *);
void (*stream_compress_init)(void *, int);
void (*stream_compress_free)(void *);
int (*stream_compress_data_to_file)(void *);
uint32_t (*stream_crc_calculate)(uint32_t, const uint8_t *, size_t);
const char *ident;
};
typedef struct file_archive_transfer
{
void *handle;
const uint8_t *footer;
const uint8_t *directory;
const uint8_t *data;
int32_t zip_size;
enum file_archive_transfer_type type;
const struct file_archive_file_backend *backend;
} file_archive_transfer_t;
/* Returns true when parsing should continue. False to stop. */
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,
uint32_t crc32, void *userdata);
int file_archive_parse_file_iterate(
file_archive_transfer_t *state,
bool *returnerr,
const char *file,
const char *valid_exts,
file_archive_file_cb file_cb,
void *userdata);
void file_archive_parse_file_iterate_stop(file_archive_transfer_t *state);
int file_archive_parse_file_progress(file_archive_transfer_t *state);
/**
* file_archive_extract_first_content_file:
* @zip_path : filename path to ZIP archive.
* @zip_path_size : size of ZIP archive.
* @valid_exts : valid extensions for a content file.
* @extraction_directory : the directory to extract temporary
* unzipped content to.
*
* Extract first content file from archive.
*
* Returns : true (1) on success, otherwise false (0).
**/
bool file_archive_extract_first_content_file(char *zip_path, size_t zip_path_size,
const char *valid_exts, const char *extraction_dir,
char *out_path, size_t len);
/**
* file_archive_get_file_list:
* @path : filename path of archive
* @valid_exts : Valid extensions of archive to be parsed.
* If NULL, allow all.
*
* 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);
bool file_archive_perform_mode(const char *name, const char *valid_exts,
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
uint32_t crc32, void *userdata);
struct string_list *compressed_file_list_new(const char *filename,
const char* ext);
void file_archive_deflate_init(void *data, int level);
const struct file_archive_file_backend *file_archive_get_default_file_backend(void);
extern const struct file_archive_file_backend zlib_backend;
#endif

View File

@ -1,70 +1,70 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (dir_list.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_DIR_LIST_H
#define __LIBRETRO_SDK_DIR_LIST_H
#include <lists/string_list.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* dir_list_new:
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : include compressed files, even when not part of ext.
*
* Create a directory listing.
*
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
* NULL in case of error. Has to be freed manually.
**/
struct string_list *dir_list_new(const char *dir, const char *ext,
bool include_dirs, bool include_compressed);
/**
* dir_list_sort:
* @list : pointer to the directory listing.
* @dir_first : move the directories in the listing to the top?
*
* Sorts a directory listing.
*
**/
void dir_list_sort(struct string_list *list, bool dir_first);
/**
* dir_list_free:
* @list : pointer to the directory listing
*
* Frees a directory listing.
*
**/
void dir_list_free(struct string_list *list);
#ifdef __cplusplus
}
#endif
#endif
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (dir_list.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_DIR_LIST_H
#define __LIBRETRO_SDK_DIR_LIST_H
#include <lists/string_list.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* dir_list_new:
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : include compressed files, even when not part of ext.
*
* Create a directory listing.
*
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
* NULL in case of error. Has to be freed manually.
**/
struct string_list *dir_list_new(const char *dir, const char *ext,
bool include_dirs, bool include_compressed);
/**
* dir_list_sort:
* @list : pointer to the directory listing.
* @dir_first : move the directories in the listing to the top?
*
* Sorts a directory listing.
*
**/
void dir_list_sort(struct string_list *list, bool dir_first);
/**
* dir_list_free:
* @list : pointer to the directory listing
*
* Frees a directory listing.
*
**/
void dir_list_free(struct string_list *list);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,119 +1,119 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_list.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_FILE_LIST_H__
#define __LIBRETRO_SDK_FILE_LIST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <stdlib.h>
#include <boolean.h>
struct item_file
{
char *path;
char *label;
char *alt;
unsigned type;
size_t directory_ptr;
size_t entry_idx;
void *userdata;
void *actiondata;
};
typedef struct file_list
{
struct item_file *list;
size_t capacity;
size_t size;
} file_list_t;
void *file_list_get_userdata_at_offset(const file_list_t *list,
size_t index);
void *file_list_get_actiondata_at_offset(const file_list_t *list,
size_t index);
void file_list_free(file_list_t *list);
bool file_list_push(file_list_t *userdata, const char *path,
const char *label, unsigned type, size_t current_directory_ptr,
size_t entry_index);
void file_list_pop(file_list_t *list, size_t *directory_ptr);
void file_list_clear(file_list_t *list);
void file_list_copy(const file_list_t *src, file_list_t *dst);
void file_list_get_last(const file_list_t *list,
const char **path, const char **label,
unsigned *type, size_t *entry_idx);
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_directory_ptr(const file_list_t *list);
void file_list_get_at_offset(const file_list_t *list, size_t index,
const char **path, const char **label,
unsigned *type, size_t *entry_idx);
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_set_label_at_offset(file_list_t *list, size_t index,
const char *label);
void file_list_get_label_at_offset(const file_list_t *list, size_t index,
const char **label);
void file_list_set_alt_at_offset(file_list_t *list, size_t index,
const char *alt);
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_get_alt_at_offset(const file_list_t *list, size_t index,
const char **alt);
void file_list_sort_on_alt(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,
size_t *index);
#ifdef __cplusplus
}
#endif
#endif
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_list.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_FILE_LIST_H__
#define __LIBRETRO_SDK_FILE_LIST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <stdlib.h>
#include <boolean.h>
struct item_file
{
char *path;
char *label;
char *alt;
unsigned type;
size_t directory_ptr;
size_t entry_idx;
void *userdata;
void *actiondata;
};
typedef struct file_list
{
struct item_file *list;
size_t capacity;
size_t size;
} file_list_t;
void *file_list_get_userdata_at_offset(const file_list_t *list,
size_t index);
void *file_list_get_actiondata_at_offset(const file_list_t *list,
size_t index);
void file_list_free(file_list_t *list);
bool file_list_push(file_list_t *userdata, const char *path,
const char *label, unsigned type, size_t current_directory_ptr,
size_t entry_index);
void file_list_pop(file_list_t *list, size_t *directory_ptr);
void file_list_clear(file_list_t *list);
void file_list_copy(const file_list_t *src, file_list_t *dst);
void file_list_get_last(const file_list_t *list,
const char **path, const char **label,
unsigned *type, size_t *entry_idx);
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_directory_ptr(const file_list_t *list);
void file_list_get_at_offset(const file_list_t *list, size_t index,
const char **path, const char **label,
unsigned *type, size_t *entry_idx);
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_set_label_at_offset(file_list_t *list, size_t index,
const char *label);
void file_list_get_label_at_offset(const file_list_t *list, size_t index,
const char **label);
void file_list_set_alt_at_offset(file_list_t *list, size_t index,
const char *alt);
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_get_alt_at_offset(const file_list_t *list, size_t index,
const char **alt);
void file_list_sort_on_alt(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,
size_t *index);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,148 +1,148 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (string_list.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_STRING_LIST_H
#define __LIBRETRO_SDK_STRING_LIST_H
#include <boolean.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
union string_list_elem_attr
{
bool b;
int i;
void *p;
};
struct string_list_elem
{
char *data;
union string_list_elem_attr attr;
};
struct string_list
{
struct string_list_elem *elems;
size_t size;
size_t cap;
};
/**
* string_list_find_elem:
* @list : pointer to string list
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
int string_list_find_elem(const struct string_list *list, const char *elem);
/**
* string_list_find_elem_prefix:
* @list : pointer to string list
* @prefix : prefix to append to @elem
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list. Will
* also search for the same element prefixed by @prefix.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
bool string_list_find_elem_prefix(const struct string_list *list,
const char *prefix, const char *elem);
/**
* string_split:
* @str : string to turn into a string list
* @delim : delimiter character to use for splitting the string.
*
* Creates a new string list based on string @str, delimited by @delim.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_split(const char *str, const char *delim);
/**
* string_list_new:
*
* Creates a new string list. Has to be freed manually.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_list_new(void);
/**
* string_list_append:
* @list : pointer to string list
* @elem : element to add to the string list
* @attr : attributes of new element.
*
* Appends a new element to the string list.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool string_list_append(struct string_list *list, const char *elem,
union string_list_elem_attr attr);
/**
* string_list_free
* @list : pointer to string list object
*
* Frees a string list.
*/
void string_list_free(struct string_list *list);
/**
* string_list_join_concat:
* @buffer : buffer that @list will be joined to.
* @size : length of @buffer.
* @list : pointer to string list.
* @delim : delimiter character for @list.
*
* A string list will be joined/concatenated as a
* string to @buffer, delimited by @delim.
*/
void string_list_join_concat(char *buffer, size_t size,
const struct string_list *list, const char *sep);
/**
* string_list_set:
* @list : pointer to string list
* @idx : index of element in string list
* @str : value for the element.
*
* Set value of element inside string list.
**/
void string_list_set(struct string_list *list, unsigned idx,
const char *str);
#ifdef __cplusplus
}
#endif
#endif
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (string_list.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_STRING_LIST_H
#define __LIBRETRO_SDK_STRING_LIST_H
#include <boolean.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
union string_list_elem_attr
{
bool b;
int i;
void *p;
};
struct string_list_elem
{
char *data;
union string_list_elem_attr attr;
};
struct string_list
{
struct string_list_elem *elems;
size_t size;
size_t cap;
};
/**
* string_list_find_elem:
* @list : pointer to string list
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
int string_list_find_elem(const struct string_list *list, const char *elem);
/**
* string_list_find_elem_prefix:
* @list : pointer to string list
* @prefix : prefix to append to @elem
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list. Will
* also search for the same element prefixed by @prefix.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
bool string_list_find_elem_prefix(const struct string_list *list,
const char *prefix, const char *elem);
/**
* string_split:
* @str : string to turn into a string list
* @delim : delimiter character to use for splitting the string.
*
* Creates a new string list based on string @str, delimited by @delim.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_split(const char *str, const char *delim);
/**
* string_list_new:
*
* Creates a new string list. Has to be freed manually.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_list_new(void);
/**
* string_list_append:
* @list : pointer to string list
* @elem : element to add to the string list
* @attr : attributes of new element.
*
* Appends a new element to the string list.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool string_list_append(struct string_list *list, const char *elem,
union string_list_elem_attr attr);
/**
* string_list_free
* @list : pointer to string list object
*
* Frees a string list.
*/
void string_list_free(struct string_list *list);
/**
* string_list_join_concat:
* @buffer : buffer that @list will be joined to.
* @size : length of @buffer.
* @list : pointer to string list.
* @delim : delimiter character for @list.
*
* A string list will be joined/concatenated as a
* string to @buffer, delimited by @delim.
*/
void string_list_join_concat(char *buffer, size_t size,
const struct string_list *list, const char *sep);
/**
* string_list_set:
* @list : pointer to string list
* @idx : index of element in string list
* @str : value for the element.
*
* Set value of element inside string list.
**/
void string_list_set(struct string_list *list, unsigned idx,
const char *str);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,49 +1,49 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (net_ifinfo.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_NET_IFINFO_H
#define _LIBRETRO_NET_IFINFO_H
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
struct net_ifinfo_entry
{
char *name;
char *host;
};
struct net_ifinfo
{
struct net_ifinfo_entry *entries;
size_t size;
};
typedef struct net_ifinfo net_ifinfo_t;
void net_ifinfo_free(net_ifinfo_t *list);
bool net_ifinfo_new(net_ifinfo_t *list);
#endif
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (net_ifinfo.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_NET_IFINFO_H
#define _LIBRETRO_NET_IFINFO_H
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
struct net_ifinfo_entry
{
char *name;
char *host;
};
struct net_ifinfo
{
struct net_ifinfo_entry *entries;
size_t size;
};
typedef struct net_ifinfo net_ifinfo_t;
void net_ifinfo_free(net_ifinfo_t *list);
bool net_ifinfo_new(net_ifinfo_t *list);
#endif

View File

@ -1,54 +1,54 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (fifo_queue.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_FIFO_BUFFER_H
#define __LIBRETRO_SDK_FIFO_BUFFER_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fifo_buffer fifo_buffer_t;
fifo_buffer_t *fifo_new(size_t size);
void fifo_clear(fifo_buffer_t *buffer);
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_free(fifo_buffer_t *buffer);
size_t fifo_read_avail(fifo_buffer_t *buffer);
size_t fifo_write_avail(fifo_buffer_t *buffer);
#ifdef __cplusplus
}
#endif
#endif
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (fifo_queue.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_FIFO_BUFFER_H
#define __LIBRETRO_SDK_FIFO_BUFFER_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fifo_buffer fifo_buffer_t;
fifo_buffer_t *fifo_new(size_t size);
void fifo_clear(fifo_buffer_t *buffer);
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_free(fifo_buffer_t *buffer);
size_t fifo_read_avail(fifo_buffer_t *buffer);
size_t fifo_write_avail(fifo_buffer_t *buffer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,75 +1,75 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_stream.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_FILE_STREAM_H
#define __LIBRETRO_SDK_FILE_STREAM_H
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include <retro_common.h>
#include <boolean.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct RFILE RFILE;
enum
{
RFILE_MODE_READ = 0,
RFILE_MODE_WRITE,
RFILE_MODE_READ_WRITE,
/* There is no garantee these requests will be attended. */
RFILE_HINT_UNBUFFERED = 1<<8,
RFILE_HINT_MMAP = 1<<9 /* requires RFILE_MODE_READ */
};
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_fread(RFILE *stream, void *s, size_t len);
ssize_t retro_fwrite(RFILE *stream, const void *s, size_t len);
ssize_t retro_ftell(RFILE *stream);
void retro_frewind(RFILE *stream);
int retro_fclose(RFILE *stream);
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);
int retro_get_fd(RFILE *stream);
#ifdef __cplusplus
}
#endif
#endif
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_stream.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_FILE_STREAM_H
#define __LIBRETRO_SDK_FILE_STREAM_H
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include <retro_common.h>
#include <boolean.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct RFILE RFILE;
enum
{
RFILE_MODE_READ = 0,
RFILE_MODE_WRITE,
RFILE_MODE_READ_WRITE,
/* There is no garantee these requests will be attended. */
RFILE_HINT_UNBUFFERED = 1<<8,
RFILE_HINT_MMAP = 1<<9 /* requires RFILE_MODE_READ */
};
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_fread(RFILE *stream, void *s, size_t len);
ssize_t retro_fwrite(RFILE *stream, const void *s, size_t len);
ssize_t retro_ftell(RFILE *stream);
void retro_frewind(RFILE *stream);
int retro_fclose(RFILE *stream);
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);
int retro_get_fd(RFILE *stream);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,51 +1,51 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (memory_stream.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
#define _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
#include <stdint.h>
#include <stddef.h>
typedef struct memstream memstream_t;
memstream_t *memstream_open(void);
void memstream_close(memstream_t * stream);
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);
int memstream_getc(memstream_t * stream);
char *memstream_gets(memstream_t * stream, char *buffer, size_t len);
size_t memstream_pos(memstream_t * stream);
int memstream_seek(memstream_t * stream, int offset, int whence);
void memstream_set_buffer(uint8_t *buffer, size_t size);
size_t memstream_get_last_size(void);
#endif
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (memory_stream.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
#define _LIBRETRO_SDK_FILE_MEMORY_STREAM_H
#include <stdint.h>
#include <stddef.h>
typedef struct memstream memstream_t;
memstream_t *memstream_open(void);
void memstream_close(memstream_t * stream);
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);
int memstream_getc(memstream_t * stream);
char *memstream_gets(memstream_t * stream, char *buffer, size_t len);
size_t memstream_pos(memstream_t * stream);
int memstream_seek(memstream_t * stream, int offset, int whence);
void memstream_set_buffer(uint8_t *buffer, size_t size);
size_t memstream_get_last_size(void);
#endif

View File

@ -1,214 +1,214 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (dir_list.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <lists/dir_list.h>
#include <lists/string_list.h>
#include <file/file_path.h>
#include <compat/strl.h>
#include <retro_dirent.h>
#include <retro_miscellaneous.h>
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 *b = (const struct string_list_elem*)b_;
return strcasecmp(a->data, b->data);
}
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 *b = (const struct string_list_elem*)b_;
int a_type = a->attr.i;
int b_type = b->attr.i;
/* Sort directories before files. */
if (a_type != b_type)
return b_type - a_type;
return strcasecmp(a->data, b->data);
}
/**
* dir_list_sort:
* @list : pointer to the directory listing.
* @dir_first : move the directories in the listing to the top?
*
* Sorts a directory listing.
*
**/
void dir_list_sort(struct string_list *list, bool dir_first)
{
if (list)
qsort(list->elems, list->size, sizeof(struct string_list_elem),
dir_first ? qstrcmp_dir : qstrcmp_plain);
}
/**
* dir_list_free:
* @list : pointer to the directory listing
*
* Frees a directory listing.
*
**/
void dir_list_free(struct string_list *list)
{
string_list_free(list);
}
/**
* parse_dir_entry:
* @name : name of the directory listing entry.
* @file_path : file path of the directory listing entry.
* @is_dir : is the directory listing a directory?
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : Include compressed files, even if not part of ext_list.
* @list : pointer to directory listing.
* @ext_list : pointer to allowed file extensions listing.
* @file_ext : file extension of the directory listing entry.
*
* Parses a directory listing.
*
* Returns: zero on success, -1 on error, 1 if we should
* continue to the next entry in the directory listing.
**/
static int parse_dir_entry(const char *name, char *file_path,
bool is_dir, bool include_dirs, bool include_compressed,
struct string_list *list, struct string_list *ext_list,
const char *file_ext)
{
union string_list_elem_attr attr;
bool is_compressed_file = false;
bool supported_by_core = false;
attr.i = RARCH_FILETYPE_UNSET;
if (!is_dir)
{
is_compressed_file = path_is_compressed_file(file_path);
if (string_list_find_elem_prefix(ext_list, ".", file_ext))
supported_by_core = true;
}
if (!include_dirs && is_dir)
return 1;
if (!strcmp(name, ".") || !strcmp(name, ".."))
return 1;
if (!is_dir && ext_list &&
((!is_compressed_file && !supported_by_core) ||
(!supported_by_core && !include_compressed)))
return 1;
if (is_dir)
attr.i = RARCH_DIRECTORY;
if (is_compressed_file)
attr.i = RARCH_COMPRESSED_ARCHIVE;
/* The order of these ifs is important.
* 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.
*
* 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.
*
* */
if (supported_by_core)
attr.i = RARCH_PLAIN_FILE;
if (!string_list_append(list, file_path, attr))
return -1;
return 0;
}
/**
* dir_list_new:
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @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.
*
* Create a directory listing.
*
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
* NULL in case of error. Has to be freed manually.
**/
struct string_list *dir_list_new(const char *dir,
const char *ext, bool include_dirs, bool include_compressed)
{
struct RDIR *entry = NULL;
struct string_list *ext_list = NULL;
struct string_list *list = NULL;
if (!(list = string_list_new()))
return NULL;
if (ext)
ext_list = string_split(ext, "|");
entry = retro_opendir(dir);
if (!entry)
goto error;
if (retro_dirent_error(entry))
goto error;
while (retro_readdir(entry))
{
char file_path[PATH_MAX_LENGTH];
bool is_dir;
int ret = 0;
const char *name = retro_dirent_get_name(entry);
const char *file_ext = path_get_extension(name);
fill_pathname_join(file_path, dir, name, sizeof(file_path));
is_dir = retro_dirent_is_dir(entry, file_path);
ret = parse_dir_entry(name, file_path, is_dir,
include_dirs, include_compressed, list, ext_list, file_ext);
if (ret == -1)
goto error;
if (ret == 1)
continue;
}
retro_closedir(entry);
string_list_free(ext_list);
return list;
error:
retro_closedir(entry);
string_list_free(list);
string_list_free(ext_list);
return NULL;
}
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (dir_list.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <lists/dir_list.h>
#include <lists/string_list.h>
#include <file/file_path.h>
#include <compat/strl.h>
#include <retro_dirent.h>
#include <retro_miscellaneous.h>
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 *b = (const struct string_list_elem*)b_;
return strcasecmp(a->data, b->data);
}
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 *b = (const struct string_list_elem*)b_;
int a_type = a->attr.i;
int b_type = b->attr.i;
/* Sort directories before files. */
if (a_type != b_type)
return b_type - a_type;
return strcasecmp(a->data, b->data);
}
/**
* dir_list_sort:
* @list : pointer to the directory listing.
* @dir_first : move the directories in the listing to the top?
*
* Sorts a directory listing.
*
**/
void dir_list_sort(struct string_list *list, bool dir_first)
{
if (list)
qsort(list->elems, list->size, sizeof(struct string_list_elem),
dir_first ? qstrcmp_dir : qstrcmp_plain);
}
/**
* dir_list_free:
* @list : pointer to the directory listing
*
* Frees a directory listing.
*
**/
void dir_list_free(struct string_list *list)
{
string_list_free(list);
}
/**
* parse_dir_entry:
* @name : name of the directory listing entry.
* @file_path : file path of the directory listing entry.
* @is_dir : is the directory listing a directory?
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : Include compressed files, even if not part of ext_list.
* @list : pointer to directory listing.
* @ext_list : pointer to allowed file extensions listing.
* @file_ext : file extension of the directory listing entry.
*
* Parses a directory listing.
*
* Returns: zero on success, -1 on error, 1 if we should
* continue to the next entry in the directory listing.
**/
static int parse_dir_entry(const char *name, char *file_path,
bool is_dir, bool include_dirs, bool include_compressed,
struct string_list *list, struct string_list *ext_list,
const char *file_ext)
{
union string_list_elem_attr attr;
bool is_compressed_file = false;
bool supported_by_core = false;
attr.i = RARCH_FILETYPE_UNSET;
if (!is_dir)
{
is_compressed_file = path_is_compressed_file(file_path);
if (string_list_find_elem_prefix(ext_list, ".", file_ext))
supported_by_core = true;
}
if (!include_dirs && is_dir)
return 1;
if (!strcmp(name, ".") || !strcmp(name, ".."))
return 1;
if (!is_dir && ext_list &&
((!is_compressed_file && !supported_by_core) ||
(!supported_by_core && !include_compressed)))
return 1;
if (is_dir)
attr.i = RARCH_DIRECTORY;
if (is_compressed_file)
attr.i = RARCH_COMPRESSED_ARCHIVE;
/* The order of these ifs is important.
* 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.
*
* 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.
*
* */
if (supported_by_core)
attr.i = RARCH_PLAIN_FILE;
if (!string_list_append(list, file_path, attr))
return -1;
return 0;
}
/**
* dir_list_new:
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @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.
*
* Create a directory listing.
*
* Returns: pointer to a directory listing of type 'struct string_list *' on success,
* NULL in case of error. Has to be freed manually.
**/
struct string_list *dir_list_new(const char *dir,
const char *ext, bool include_dirs, bool include_compressed)
{
struct RDIR *entry = NULL;
struct string_list *ext_list = NULL;
struct string_list *list = NULL;
if (!(list = string_list_new()))
return NULL;
if (ext)
ext_list = string_split(ext, "|");
entry = retro_opendir(dir);
if (!entry)
goto error;
if (retro_dirent_error(entry))
goto error;
while (retro_readdir(entry))
{
char file_path[PATH_MAX_LENGTH];
bool is_dir;
int ret = 0;
const char *name = retro_dirent_get_name(entry);
const char *file_ext = path_get_extension(name);
fill_pathname_join(file_path, dir, name, sizeof(file_path));
is_dir = retro_dirent_is_dir(entry, file_path);
ret = parse_dir_entry(name, file_path, is_dir,
include_dirs, include_compressed, list, ext_list, file_ext);
if (ret == -1)
goto error;
if (ret == 1)
continue;
}
retro_closedir(entry);
string_list_free(ext_list);
return list;
error:
retro_closedir(entry);
string_list_free(list);
string_list_free(ext_list);
return NULL;
}

View File

@ -1,428 +1,428 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_list.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <retro_assert.h>
#include <retro_common.h>
#include <lists/file_list.h>
#include <compat/strcasestr.h>
/**
* file_list_capacity:
* @list : pointer to file list
* @cap : new capacity for file list.
*
* Change maximum capacity of file list's size.
*
* Returns: true (1) if successful, otherwise false (0).
**/
static bool file_list_capacity(file_list_t *list, size_t cap)
{
struct item_file *new_data = NULL;
retro_assert(cap > list->size);
new_data = (struct item_file*)realloc(list->list,
cap * sizeof(struct item_file));
if (!new_data)
return false;
if (cap > list->capacity)
memset(&new_data[list->capacity], 0,
sizeof(*new_data) * (cap - list->capacity));
list->list = new_data;
list->capacity = cap;
return true;
}
bool file_list_push(file_list_t *list,
const char *path, const char *label,
unsigned type, size_t directory_ptr,
size_t entry_idx)
{
if (list->size >= list->capacity &&
!file_list_capacity(list, list->capacity * 2 + 1))
return false;
list->list[list->size].label = NULL;
list->list[list->size].path = NULL;
list->list[list->size].alt = NULL;
list->list[list->size].userdata = NULL;
list->list[list->size].actiondata = NULL;
list->list[list->size].type = type;
list->list[list->size].directory_ptr = directory_ptr;
list->list[list->size].entry_idx = entry_idx;
if (label)
list->list[list->size].label = strdup(label);
if (path)
list->list[list->size].path = strdup(path);
list->size++;
return true;
}
size_t file_list_get_size(const file_list_t *list)
{
if (!list)
return 0;
return list->size;
}
size_t file_list_get_directory_ptr(const file_list_t *list)
{
size_t size = file_list_get_size(list);
return list->list[size].directory_ptr;
}
void file_list_pop(file_list_t *list, size_t *directory_ptr)
{
if (!list)
return;
if (list->size != 0)
{
--list->size;
if (list->list[list->size].path)
free(list->list[list->size].path);
list->list[list->size].path = NULL;
if (list->list[list->size].label)
free(list->list[list->size].label);
list->list[list->size].label = NULL;
}
if (directory_ptr)
*directory_ptr = list->list[list->size].directory_ptr;
}
void file_list_free(file_list_t *list)
{
size_t i;
if (!list)
return;
for (i = 0; i < list->size; i++)
{
file_list_free_userdata(list, i);
file_list_free_actiondata(list, i);
if (list->list[i].path)
free(list->list[i].path);
list->list[i].path = NULL;
if (list->list[i].label)
free(list->list[i].label);
list->list[i].label = NULL;
if (list->list[i].alt)
free(list->list[i].alt);
list->list[i].alt = NULL;
}
if (list->list)
free(list->list);
list->list = NULL;
free(list);
}
void file_list_clear(file_list_t *list)
{
size_t i;
if (!list)
return;
for (i = 0; i < list->size; i++)
{
if (list->list[i].path)
free(list->list[i].path);
list->list[i].path = NULL;
if (list->list[i].label)
free(list->list[i].label);
list->list[i].label = NULL;
if (list->list[i].alt)
free(list->list[i].alt);
list->list[i].alt = NULL;
}
list->size = 0;
}
void file_list_copy(const file_list_t *src, file_list_t *dst)
{
struct item_file *item;
if (!src || !dst)
return;
if (dst->list)
{
for (item = dst->list; item < &dst->list[dst->size]; ++item)
{
if (item->path)
free(item->path);
if (item->label)
free(item->label);
if (item->alt)
free(item->alt);
}
free(dst->list);
}
dst->size = 0;
dst->capacity = 0;
dst->list = (struct item_file*)malloc(src->size * sizeof(struct item_file));
if (!dst->list)
return;
dst->size = dst->capacity = src->size;
memcpy(dst->list, src->list, dst->size * sizeof(struct item_file));
for (item = dst->list; item < &dst->list[dst->size]; ++item)
{
if (item->path)
item->path = strdup(item->path);
if (item->label)
item->label = strdup(item->label);
if (item->alt)
item->alt = strdup(item->alt);
}
}
void file_list_set_label_at_offset(file_list_t *list, size_t idx,
const char *label)
{
if (!list)
return;
if (list->list[idx].label)
free(list->list[idx].label);
list->list[idx].alt = NULL;
if (label)
list->list[idx].label = strdup(label);
}
void file_list_get_label_at_offset(const file_list_t *list, size_t idx,
const char **label)
{
if (!label || !list)
return;
*label = list->list[idx].path;
if (list->list[idx].label)
*label = list->list[idx].label;
}
void file_list_set_alt_at_offset(file_list_t *list, size_t idx,
const char *alt)
{
if (!list || !alt)
return;
if (list->list[idx].alt)
free(list->list[idx].alt);
list->list[idx].alt = NULL;
if (alt)
list->list[idx].alt = strdup(alt);
}
void file_list_get_alt_at_offset(const file_list_t *list, size_t idx,
const char **alt)
{
if (!list)
return;
if (alt)
*alt = list->list[idx].alt ?
list->list[idx].alt : list->list[idx].path;
}
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 *b = (const struct item_file*)b_;
const char *cmp_a = a->alt ? a->alt : a->path;
const char *cmp_b = b->alt ? b->alt : b->path;
return strcasecmp(cmp_a, cmp_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 *b = (const struct item_file*)b_;
if (a->type < b->type)
return -1;
if (a->type == b->type)
return 0;
return 1;
}
void file_list_sort_on_alt(file_list_t *list)
{
qsort(list->list, list->size, sizeof(list->list[0]), file_list_alt_cmp);
}
void file_list_sort_on_type(file_list_t *list)
{
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)
{
if (!list)
return NULL;
return list->list[idx].userdata;
}
void file_list_set_userdata(const file_list_t *list, size_t idx, void *ptr)
{
if (!list || !ptr)
return;
list->list[idx].userdata = ptr;
}
void file_list_set_actiondata(const file_list_t *list, size_t idx, void *ptr)
{
if (!list || !ptr)
return;
list->list[idx].actiondata = ptr;
}
void *file_list_get_actiondata_at_offset(const file_list_t *list, size_t idx)
{
if (!list)
return NULL;
return list->list[idx].actiondata;
}
void file_list_free_actiondata(const file_list_t *list, size_t idx)
{
if (!list)
return;
if (list->list[idx].actiondata)
free(list->list[idx].actiondata);
list->list[idx].actiondata = NULL;
}
void file_list_free_userdata(const file_list_t *list, size_t idx)
{
if (!list)
return;
if (list->list[idx].userdata)
free(list->list[idx].userdata);
list->list[idx].userdata = NULL;
}
void *file_list_get_last_actiondata(const file_list_t *list)
{
if (!list)
return NULL;
return list->list[list->size - 1].actiondata;
}
void file_list_get_at_offset(const file_list_t *list, size_t idx,
const char **path, const char **label, unsigned *file_type,
size_t *entry_idx)
{
if (!list)
return;
if (path)
*path = list->list[idx].path;
if (label)
*label = list->list[idx].label;
if (file_type)
*file_type = list->list[idx].type;
if (entry_idx)
*entry_idx = list->list[idx].entry_idx;
}
void file_list_get_last(const file_list_t *list,
const char **path, const char **label,
unsigned *file_type, size_t *entry_idx)
{
if (!list)
return;
if (list->size)
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)
{
size_t i;
const char *alt;
bool ret = false;
if (!list)
return false;
for (i = 0; i < list->size; i++)
{
const char *str;
file_list_get_alt_at_offset(list, i, &alt);
if (!alt)
{
file_list_get_label_at_offset(list, i, &alt);
if (!alt)
continue;
}
str = (const char *)strcasestr(alt, needle);
if (str == alt)
{
/* Found match with first chars, best possible match. */
*idx = i;
ret = true;
break;
}
else if (str && !ret)
{
/* Found mid-string match, but try to find a match with
* first characters before we settle. */
*idx = i;
ret = true;
}
}
return ret;
}
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_list.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <retro_assert.h>
#include <retro_common.h>
#include <lists/file_list.h>
#include <compat/strcasestr.h>
/**
* file_list_capacity:
* @list : pointer to file list
* @cap : new capacity for file list.
*
* Change maximum capacity of file list's size.
*
* Returns: true (1) if successful, otherwise false (0).
**/
static bool file_list_capacity(file_list_t *list, size_t cap)
{
struct item_file *new_data = NULL;
retro_assert(cap > list->size);
new_data = (struct item_file*)realloc(list->list,
cap * sizeof(struct item_file));
if (!new_data)
return false;
if (cap > list->capacity)
memset(&new_data[list->capacity], 0,
sizeof(*new_data) * (cap - list->capacity));
list->list = new_data;
list->capacity = cap;
return true;
}
bool file_list_push(file_list_t *list,
const char *path, const char *label,
unsigned type, size_t directory_ptr,
size_t entry_idx)
{
if (list->size >= list->capacity &&
!file_list_capacity(list, list->capacity * 2 + 1))
return false;
list->list[list->size].label = NULL;
list->list[list->size].path = NULL;
list->list[list->size].alt = NULL;
list->list[list->size].userdata = NULL;
list->list[list->size].actiondata = NULL;
list->list[list->size].type = type;
list->list[list->size].directory_ptr = directory_ptr;
list->list[list->size].entry_idx = entry_idx;
if (label)
list->list[list->size].label = strdup(label);
if (path)
list->list[list->size].path = strdup(path);
list->size++;
return true;
}
size_t file_list_get_size(const file_list_t *list)
{
if (!list)
return 0;
return list->size;
}
size_t file_list_get_directory_ptr(const file_list_t *list)
{
size_t size = file_list_get_size(list);
return list->list[size].directory_ptr;
}
void file_list_pop(file_list_t *list, size_t *directory_ptr)
{
if (!list)
return;
if (list->size != 0)
{
--list->size;
if (list->list[list->size].path)
free(list->list[list->size].path);
list->list[list->size].path = NULL;
if (list->list[list->size].label)
free(list->list[list->size].label);
list->list[list->size].label = NULL;
}
if (directory_ptr)
*directory_ptr = list->list[list->size].directory_ptr;
}
void file_list_free(file_list_t *list)
{
size_t i;
if (!list)
return;
for (i = 0; i < list->size; i++)
{
file_list_free_userdata(list, i);
file_list_free_actiondata(list, i);
if (list->list[i].path)
free(list->list[i].path);
list->list[i].path = NULL;
if (list->list[i].label)
free(list->list[i].label);
list->list[i].label = NULL;
if (list->list[i].alt)
free(list->list[i].alt);
list->list[i].alt = NULL;
}
if (list->list)
free(list->list);
list->list = NULL;
free(list);
}
void file_list_clear(file_list_t *list)
{
size_t i;
if (!list)
return;
for (i = 0; i < list->size; i++)
{
if (list->list[i].path)
free(list->list[i].path);
list->list[i].path = NULL;
if (list->list[i].label)
free(list->list[i].label);
list->list[i].label = NULL;
if (list->list[i].alt)
free(list->list[i].alt);
list->list[i].alt = NULL;
}
list->size = 0;
}
void file_list_copy(const file_list_t *src, file_list_t *dst)
{
struct item_file *item;
if (!src || !dst)
return;
if (dst->list)
{
for (item = dst->list; item < &dst->list[dst->size]; ++item)
{
if (item->path)
free(item->path);
if (item->label)
free(item->label);
if (item->alt)
free(item->alt);
}
free(dst->list);
}
dst->size = 0;
dst->capacity = 0;
dst->list = (struct item_file*)malloc(src->size * sizeof(struct item_file));
if (!dst->list)
return;
dst->size = dst->capacity = src->size;
memcpy(dst->list, src->list, dst->size * sizeof(struct item_file));
for (item = dst->list; item < &dst->list[dst->size]; ++item)
{
if (item->path)
item->path = strdup(item->path);
if (item->label)
item->label = strdup(item->label);
if (item->alt)
item->alt = strdup(item->alt);
}
}
void file_list_set_label_at_offset(file_list_t *list, size_t idx,
const char *label)
{
if (!list)
return;
if (list->list[idx].label)
free(list->list[idx].label);
list->list[idx].alt = NULL;
if (label)
list->list[idx].label = strdup(label);
}
void file_list_get_label_at_offset(const file_list_t *list, size_t idx,
const char **label)
{
if (!label || !list)
return;
*label = list->list[idx].path;
if (list->list[idx].label)
*label = list->list[idx].label;
}
void file_list_set_alt_at_offset(file_list_t *list, size_t idx,
const char *alt)
{
if (!list || !alt)
return;
if (list->list[idx].alt)
free(list->list[idx].alt);
list->list[idx].alt = NULL;
if (alt)
list->list[idx].alt = strdup(alt);
}
void file_list_get_alt_at_offset(const file_list_t *list, size_t idx,
const char **alt)
{
if (!list)
return;
if (alt)
*alt = list->list[idx].alt ?
list->list[idx].alt : list->list[idx].path;
}
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 *b = (const struct item_file*)b_;
const char *cmp_a = a->alt ? a->alt : a->path;
const char *cmp_b = b->alt ? b->alt : b->path;
return strcasecmp(cmp_a, cmp_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 *b = (const struct item_file*)b_;
if (a->type < b->type)
return -1;
if (a->type == b->type)
return 0;
return 1;
}
void file_list_sort_on_alt(file_list_t *list)
{
qsort(list->list, list->size, sizeof(list->list[0]), file_list_alt_cmp);
}
void file_list_sort_on_type(file_list_t *list)
{
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)
{
if (!list)
return NULL;
return list->list[idx].userdata;
}
void file_list_set_userdata(const file_list_t *list, size_t idx, void *ptr)
{
if (!list || !ptr)
return;
list->list[idx].userdata = ptr;
}
void file_list_set_actiondata(const file_list_t *list, size_t idx, void *ptr)
{
if (!list || !ptr)
return;
list->list[idx].actiondata = ptr;
}
void *file_list_get_actiondata_at_offset(const file_list_t *list, size_t idx)
{
if (!list)
return NULL;
return list->list[idx].actiondata;
}
void file_list_free_actiondata(const file_list_t *list, size_t idx)
{
if (!list)
return;
if (list->list[idx].actiondata)
free(list->list[idx].actiondata);
list->list[idx].actiondata = NULL;
}
void file_list_free_userdata(const file_list_t *list, size_t idx)
{
if (!list)
return;
if (list->list[idx].userdata)
free(list->list[idx].userdata);
list->list[idx].userdata = NULL;
}
void *file_list_get_last_actiondata(const file_list_t *list)
{
if (!list)
return NULL;
return list->list[list->size - 1].actiondata;
}
void file_list_get_at_offset(const file_list_t *list, size_t idx,
const char **path, const char **label, unsigned *file_type,
size_t *entry_idx)
{
if (!list)
return;
if (path)
*path = list->list[idx].path;
if (label)
*label = list->list[idx].label;
if (file_type)
*file_type = list->list[idx].type;
if (entry_idx)
*entry_idx = list->list[idx].entry_idx;
}
void file_list_get_last(const file_list_t *list,
const char **path, const char **label,
unsigned *file_type, size_t *entry_idx)
{
if (!list)
return;
if (list->size)
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)
{
size_t i;
const char *alt;
bool ret = false;
if (!list)
return false;
for (i = 0; i < list->size; i++)
{
const char *str;
file_list_get_alt_at_offset(list, i, &alt);
if (!alt)
{
file_list_get_label_at_offset(list, i, &alt);
if (!alt)
continue;
}
str = (const char *)strcasestr(alt, needle);
if (str == alt)
{
/* Found match with first chars, best possible match. */
*idx = i;
ret = true;
break;
}
else if (str && !ret)
{
/* Found mid-string match, but try to find a match with
* first characters before we settle. */
*idx = i;
ret = true;
}
}
return ret;
}

View File

@ -1,275 +1,275 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (string_list.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <lists/string_list.h>
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
/**
* string_list_free
* @list : pointer to string list object
*
* Frees a string list.
*/
void string_list_free(struct string_list *list)
{
size_t i;
if (!list)
return;
for (i = 0; i < list->size; i++)
free(list->elems[i].data);
free(list->elems);
free(list);
}
/**
* string_list_capacity:
* @list : pointer to string list
* @cap : new capacity for string list.
*
* Change maximum capacity of string list's size.
*
* Returns: true (1) if successful, otherwise false (0).
**/
static bool string_list_capacity(struct string_list *list, size_t cap)
{
struct string_list_elem *new_data = NULL;
retro_assert(cap > list->size);
new_data = (struct string_list_elem*)
realloc(list->elems, cap * sizeof(*new_data));
if (!new_data)
return false;
if (cap > list->cap)
memset(&new_data[list->cap], 0, sizeof(*new_data) * (cap - list->cap));
list->elems = new_data;
list->cap = cap;
return true;
}
/**
* string_list_new:
*
* Creates a new string list. Has to be freed manually.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_list_new(void)
{
struct string_list *list = (struct string_list*)
calloc(1, sizeof(*list));
if (!list)
return NULL;
if (!string_list_capacity(list, 32))
{
string_list_free(list);
return NULL;
}
return list;
}
/**
* string_list_append:
* @list : pointer to string list
* @elem : element to add to the string list
* @attr : attributes of new element.
*
* Appends a new element to the string list.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool string_list_append(struct string_list *list, const char *elem,
union string_list_elem_attr attr)
{
char *data_dup = NULL;
if (list->size >= list->cap &&
!string_list_capacity(list, list->cap * 2))
return false;
data_dup = strdup(elem);
if (!data_dup)
return false;
list->elems[list->size].data = data_dup;
list->elems[list->size].attr = attr;
list->size++;
return true;
}
/**
* string_list_set:
* @list : pointer to string list
* @idx : index of element in string list
* @str : value for the element.
*
* Set value of element inside string list.
**/
void string_list_set(struct string_list *list,
unsigned idx, const char *str)
{
free(list->elems[idx].data);
retro_assert(list->elems[idx].data = strdup(str));
}
/**
* string_list_join_concat:
* @buffer : buffer that @list will be joined to.
* @size : length of @buffer.
* @list : pointer to string list.
* @delim : delimiter character for @list.
*
* A string list will be joined/concatenated as a
* string to @buffer, delimited by @delim.
*/
void string_list_join_concat(char *buffer, size_t size,
const struct string_list *list, const char *delim)
{
size_t i, len = strlen(buffer);
retro_assert(len < size);
buffer += len;
size -= len;
for (i = 0; i < list->size; i++)
{
strlcat(buffer, list->elems[i].data, size);
if ((i + 1) < list->size)
strlcat(buffer, delim, size);
}
}
/**
* string_split:
* @str : string to turn into a string list
* @delim : delimiter character to use for splitting the string.
*
* Creates a new string list based on string @str, delimited by @delim.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_split(const char *str, const char *delim)
{
char *save = NULL;
char *copy = NULL;
const char *tmp = NULL;
struct string_list *list = string_list_new();
if (!list)
goto error;
copy = strdup(str);
if (!copy)
goto error;
tmp = strtok_r(copy, delim, &save);
while (tmp)
{
union string_list_elem_attr attr;
memset(&attr, 0, sizeof(attr));
if (!string_list_append(list, tmp, attr))
goto error;
tmp = strtok_r(NULL, delim, &save);
}
free(copy);
return list;
error:
string_list_free(list);
free(copy);
return NULL;
}
/**
* string_list_find_elem:
* @list : pointer to string list
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
int string_list_find_elem(const struct string_list *list, const char *elem)
{
size_t i;
if (!list)
return false;
for (i = 0; i < list->size; i++)
{
if (strcasecmp(list->elems[i].data, elem) == 0)
return i+1;
}
return false;
}
/**
* string_list_find_elem_prefix:
* @list : pointer to string list
* @prefix : prefix to append to @elem
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list. Will
* also search for the same element prefixed by @prefix.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
bool string_list_find_elem_prefix(const struct string_list *list,
const char *prefix, const char *elem)
{
size_t i;
char prefixed[PATH_MAX_LENGTH] = {0};
if (!list)
return false;
strlcpy(prefixed, prefix, sizeof(prefixed));
strlcat(prefixed, elem, sizeof(prefixed));
for (i = 0; i < list->size; i++)
{
if (strcasecmp(list->elems[i].data, elem) == 0 ||
strcasecmp(list->elems[i].data, prefixed) == 0)
return true;
}
return false;
}
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (string_list.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <lists/string_list.h>
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
/**
* string_list_free
* @list : pointer to string list object
*
* Frees a string list.
*/
void string_list_free(struct string_list *list)
{
size_t i;
if (!list)
return;
for (i = 0; i < list->size; i++)
free(list->elems[i].data);
free(list->elems);
free(list);
}
/**
* string_list_capacity:
* @list : pointer to string list
* @cap : new capacity for string list.
*
* Change maximum capacity of string list's size.
*
* Returns: true (1) if successful, otherwise false (0).
**/
static bool string_list_capacity(struct string_list *list, size_t cap)
{
struct string_list_elem *new_data = NULL;
retro_assert(cap > list->size);
new_data = (struct string_list_elem*)
realloc(list->elems, cap * sizeof(*new_data));
if (!new_data)
return false;
if (cap > list->cap)
memset(&new_data[list->cap], 0, sizeof(*new_data) * (cap - list->cap));
list->elems = new_data;
list->cap = cap;
return true;
}
/**
* string_list_new:
*
* Creates a new string list. Has to be freed manually.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_list_new(void)
{
struct string_list *list = (struct string_list*)
calloc(1, sizeof(*list));
if (!list)
return NULL;
if (!string_list_capacity(list, 32))
{
string_list_free(list);
return NULL;
}
return list;
}
/**
* string_list_append:
* @list : pointer to string list
* @elem : element to add to the string list
* @attr : attributes of new element.
*
* Appends a new element to the string list.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool string_list_append(struct string_list *list, const char *elem,
union string_list_elem_attr attr)
{
char *data_dup = NULL;
if (list->size >= list->cap &&
!string_list_capacity(list, list->cap * 2))
return false;
data_dup = strdup(elem);
if (!data_dup)
return false;
list->elems[list->size].data = data_dup;
list->elems[list->size].attr = attr;
list->size++;
return true;
}
/**
* string_list_set:
* @list : pointer to string list
* @idx : index of element in string list
* @str : value for the element.
*
* Set value of element inside string list.
**/
void string_list_set(struct string_list *list,
unsigned idx, const char *str)
{
free(list->elems[idx].data);
retro_assert(list->elems[idx].data = strdup(str));
}
/**
* string_list_join_concat:
* @buffer : buffer that @list will be joined to.
* @size : length of @buffer.
* @list : pointer to string list.
* @delim : delimiter character for @list.
*
* A string list will be joined/concatenated as a
* string to @buffer, delimited by @delim.
*/
void string_list_join_concat(char *buffer, size_t size,
const struct string_list *list, const char *delim)
{
size_t i, len = strlen(buffer);
retro_assert(len < size);
buffer += len;
size -= len;
for (i = 0; i < list->size; i++)
{
strlcat(buffer, list->elems[i].data, size);
if ((i + 1) < list->size)
strlcat(buffer, delim, size);
}
}
/**
* string_split:
* @str : string to turn into a string list
* @delim : delimiter character to use for splitting the string.
*
* Creates a new string list based on string @str, delimited by @delim.
*
* Returns: new string list if successful, otherwise NULL.
*/
struct string_list *string_split(const char *str, const char *delim)
{
char *save = NULL;
char *copy = NULL;
const char *tmp = NULL;
struct string_list *list = string_list_new();
if (!list)
goto error;
copy = strdup(str);
if (!copy)
goto error;
tmp = strtok_r(copy, delim, &save);
while (tmp)
{
union string_list_elem_attr attr;
memset(&attr, 0, sizeof(attr));
if (!string_list_append(list, tmp, attr))
goto error;
tmp = strtok_r(NULL, delim, &save);
}
free(copy);
return list;
error:
string_list_free(list);
free(copy);
return NULL;
}
/**
* string_list_find_elem:
* @list : pointer to string list
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
int string_list_find_elem(const struct string_list *list, const char *elem)
{
size_t i;
if (!list)
return false;
for (i = 0; i < list->size; i++)
{
if (strcasecmp(list->elems[i].data, elem) == 0)
return i+1;
}
return false;
}
/**
* string_list_find_elem_prefix:
* @list : pointer to string list
* @prefix : prefix to append to @elem
* @elem : element to find inside the string list.
*
* Searches for an element (@elem) inside the string list. Will
* also search for the same element prefixed by @prefix.
*
* Returns: true (1) if element could be found, otherwise false (0).
*/
bool string_list_find_elem_prefix(const struct string_list *list,
const char *prefix, const char *elem)
{
size_t i;
char prefixed[PATH_MAX_LENGTH] = {0};
if (!list)
return false;
strlcpy(prefixed, prefix, sizeof(prefixed));
strlcat(prefixed, elem, sizeof(prefixed));
for (i = 0; i < list->size; i++)
{
if (strcasecmp(list->elems[i].data, elem) == 0 ||
strcasecmp(list->elems[i].data, prefixed) == 0)
return true;
}
return false;
}

View File

@ -1,178 +1,178 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_fnmatch.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <retro_miscellaneous.h>
#if defined(_WIN32) && !defined(_XBOX)
#include <winsock2.h>
#include <IPHlpApi.h>
#include <WS2tcpip.h>
#else
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#ifdef WANT_IFADDRS
#include <compat/ifaddrs.h>
#else
#include <ifaddrs.h>
#endif
#endif
#include <net/net_ifinfo.h>
void net_ifinfo_free(net_ifinfo_t *list)
{
unsigned k;
if (!list)
return;
for (k = 0; k < list->size; k++)
{
struct net_ifinfo_entry *ptr =
(struct net_ifinfo_entry*)&list->entries[k];
if (!ptr)
continue;
if (*ptr->name)
free(ptr->name);
if (*ptr->host)
free(ptr->host);
ptr->name = NULL;
ptr->host = NULL;
}
free(list->entries);
free(list);
}
bool net_ifinfo_new(net_ifinfo_t *list)
{
unsigned k = 0;
#if defined(_WIN32) && !defined(_XBOX)
DWORD size;
PIP_ADAPTER_ADDRESSES adapter_addresses, aa;
PIP_ADAPTER_UNICAST_ADDRESS ua;
DWORD rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, NULL, &size);
adapter_addresses = (PIP_ADAPTER_ADDRESSES)malloc(size);
rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, adapter_addresses, &size);
if (rv != ERROR_SUCCESS)
goto error;
for (aa = adapter_addresses; aa != NULL; aa = aa->Next)
{
char name[PATH_MAX_LENGTH];
memset(name, 0, sizeof(name));
WideCharToMultiByte(CP_ACP, 0, aa->FriendlyName, wcslen(aa->FriendlyName),
name, PATH_MAX_LENGTH, NULL, NULL);
for (ua = aa->FirstUnicastAddress; ua != NULL; ua = ua->Next)
{
char host[PATH_MAX_LENGTH];
struct net_ifinfo_entry *ptr = (struct net_ifinfo_entry*)
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
if (!ptr)
goto error;
list->entries = ptr;
memset(host, 0, sizeof(host));
getnameinfo(ua->Address.lpSockaddr, ua->Address.iSockaddrLength,
host, sizeof(host), NULL, NI_MAXSERV, NI_NUMERICHOST);
list->entries[k].name = strdup(name);
list->entries[k].host = strdup(host);
list->size = k + 1;
k++;
}
}
free(adapter_addresses);
#else
struct ifaddrs *ifa = NULL;
struct ifaddrs *ifaddr = NULL;
if (getifaddrs(&ifaddr) == -1)
goto error;
if (!list)
goto error;
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
char host[NI_MAXHOST];
struct net_ifinfo_entry *ptr = NULL;
if (!ifa->ifa_addr)
continue;
if (ifa->ifa_addr->sa_family != AF_INET)
continue;
if (getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0)
goto error;
ptr = (struct net_ifinfo_entry*)
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
if (!ptr)
goto error;
list->entries = ptr;
list->entries[k].name = strdup(ifa->ifa_name);
list->entries[k].host = strdup(host);
list->size = k + 1;
k++;
}
freeifaddrs(ifaddr);
#endif
return true;
error:
#ifdef _WIN32
if (adapter_addresses)
free(adapter_addresses);
#else
freeifaddrs(ifaddr);
#endif
net_ifinfo_free(list);
return false;
}
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_fnmatch.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <retro_miscellaneous.h>
#if defined(_WIN32) && !defined(_XBOX)
#include <winsock2.h>
#include <IPHlpApi.h>
#include <WS2tcpip.h>
#else
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#ifdef WANT_IFADDRS
#include <compat/ifaddrs.h>
#else
#include <ifaddrs.h>
#endif
#endif
#include <net/net_ifinfo.h>
void net_ifinfo_free(net_ifinfo_t *list)
{
unsigned k;
if (!list)
return;
for (k = 0; k < list->size; k++)
{
struct net_ifinfo_entry *ptr =
(struct net_ifinfo_entry*)&list->entries[k];
if (!ptr)
continue;
if (*ptr->name)
free(ptr->name);
if (*ptr->host)
free(ptr->host);
ptr->name = NULL;
ptr->host = NULL;
}
free(list->entries);
free(list);
}
bool net_ifinfo_new(net_ifinfo_t *list)
{
unsigned k = 0;
#if defined(_WIN32) && !defined(_XBOX)
DWORD size;
PIP_ADAPTER_ADDRESSES adapter_addresses, aa;
PIP_ADAPTER_UNICAST_ADDRESS ua;
DWORD rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, NULL, &size);
adapter_addresses = (PIP_ADAPTER_ADDRESSES)malloc(size);
rv = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, adapter_addresses, &size);
if (rv != ERROR_SUCCESS)
goto error;
for (aa = adapter_addresses; aa != NULL; aa = aa->Next)
{
char name[PATH_MAX_LENGTH];
memset(name, 0, sizeof(name));
WideCharToMultiByte(CP_ACP, 0, aa->FriendlyName, wcslen(aa->FriendlyName),
name, PATH_MAX_LENGTH, NULL, NULL);
for (ua = aa->FirstUnicastAddress; ua != NULL; ua = ua->Next)
{
char host[PATH_MAX_LENGTH];
struct net_ifinfo_entry *ptr = (struct net_ifinfo_entry*)
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
if (!ptr)
goto error;
list->entries = ptr;
memset(host, 0, sizeof(host));
getnameinfo(ua->Address.lpSockaddr, ua->Address.iSockaddrLength,
host, sizeof(host), NULL, NI_MAXSERV, NI_NUMERICHOST);
list->entries[k].name = strdup(name);
list->entries[k].host = strdup(host);
list->size = k + 1;
k++;
}
}
free(adapter_addresses);
#else
struct ifaddrs *ifa = NULL;
struct ifaddrs *ifaddr = NULL;
if (getifaddrs(&ifaddr) == -1)
goto error;
if (!list)
goto error;
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
char host[NI_MAXHOST];
struct net_ifinfo_entry *ptr = NULL;
if (!ifa->ifa_addr)
continue;
if (ifa->ifa_addr->sa_family != AF_INET)
continue;
if (getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0)
goto error;
ptr = (struct net_ifinfo_entry*)
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
if (!ptr)
goto error;
list->entries = ptr;
list->entries[k].name = strdup(ifa->ifa_name);
list->entries[k].host = strdup(host);
list->size = k + 1;
k++;
}
freeifaddrs(ifaddr);
#endif
return true;
error:
#ifdef _WIN32
if (adapter_addresses)
free(adapter_addresses);
#else
freeifaddrs(ifaddr);
#endif
net_ifinfo_free(list);
return false;
}

View File

@ -1,49 +1,49 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_fnmatch.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <net/net_ifinfo.h>
int main(int argc, const char *argv[])
{
unsigned k = 0;
net_ifinfo_t *list =
(net_ifinfo_t*)calloc(1, sizeof(*list));
if (!list)
return -1;
if (!net_ifinfo_new(list))
return -1;
for (k = 0; k < list->size; k++)
{
printf("%s:%s\n", list->entries[k].name, list->entries[k].host);
}
net_ifinfo_free(list);
return 0;
}
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (compat_fnmatch.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <net/net_ifinfo.h>
int main(int argc, const char *argv[])
{
unsigned k = 0;
net_ifinfo_t *list =
(net_ifinfo_t*)calloc(1, sizeof(*list));
if (!list)
return -1;
if (!net_ifinfo_new(list))
return -1;
for (k = 0; k < list->size; k++)
{
printf("%s:%s\n", list->entries[k].name, list->entries[k].host);
}
net_ifinfo_free(list);
return 0;
}

View File

@ -1,124 +1,124 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (fifo_queue.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <queues/fifo_queue.h>
struct fifo_buffer
{
uint8_t *buffer;
size_t size;
size_t first;
size_t end;
};
fifo_buffer_t *fifo_new(size_t size)
{
fifo_buffer_t *buf = (fifo_buffer_t*)calloc(1, sizeof(*buf));
if (!buf)
return NULL;
buf->buffer = (uint8_t*)calloc(1, size + 1);
if (!buf->buffer)
{
free(buf);
return NULL;
}
buf->size = size + 1;
return buf;
}
void fifo_clear(fifo_buffer_t *buffer)
{
buffer->first = 0;
buffer->end = 0;
}
void fifo_free(fifo_buffer_t *buffer)
{
if (!buffer)
return;
free(buffer->buffer);
free(buffer);
}
size_t fifo_read_avail(fifo_buffer_t *buffer)
{
size_t first = buffer->first;
size_t end = buffer->end;
if (end < first)
end += buffer->size;
return end - first;
}
size_t fifo_write_avail(fifo_buffer_t *buffer)
{
size_t first = buffer->first;
size_t end = buffer->end;
if (end < first)
end += buffer->size;
return (buffer->size - 1) - (end - first);
}
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size)
{
size_t first_write = size;
size_t rest_write = 0;
if (buffer->end + size > buffer->size)
{
first_write = buffer->size - buffer->end;
rest_write = size - first_write;
}
memcpy(buffer->buffer + buffer->end, in_buf, first_write);
memcpy(buffer->buffer, (const uint8_t*)in_buf + first_write, rest_write);
buffer->end = (buffer->end + size) % buffer->size;
}
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size)
{
size_t first_read = size;
size_t rest_read = 0;
if (buffer->first + size > buffer->size)
{
first_read = buffer->size - buffer->first;
rest_read = size - 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);
buffer->first = (buffer->first + size) % buffer->size;
}
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (fifo_queue.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <queues/fifo_queue.h>
struct fifo_buffer
{
uint8_t *buffer;
size_t size;
size_t first;
size_t end;
};
fifo_buffer_t *fifo_new(size_t size)
{
fifo_buffer_t *buf = (fifo_buffer_t*)calloc(1, sizeof(*buf));
if (!buf)
return NULL;
buf->buffer = (uint8_t*)calloc(1, size + 1);
if (!buf->buffer)
{
free(buf);
return NULL;
}
buf->size = size + 1;
return buf;
}
void fifo_clear(fifo_buffer_t *buffer)
{
buffer->first = 0;
buffer->end = 0;
}
void fifo_free(fifo_buffer_t *buffer)
{
if (!buffer)
return;
free(buffer->buffer);
free(buffer);
}
size_t fifo_read_avail(fifo_buffer_t *buffer)
{
size_t first = buffer->first;
size_t end = buffer->end;
if (end < first)
end += buffer->size;
return end - first;
}
size_t fifo_write_avail(fifo_buffer_t *buffer)
{
size_t first = buffer->first;
size_t end = buffer->end;
if (end < first)
end += buffer->size;
return (buffer->size - 1) - (end - first);
}
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size)
{
size_t first_write = size;
size_t rest_write = 0;
if (buffer->end + size > buffer->size)
{
first_write = buffer->size - buffer->end;
rest_write = size - first_write;
}
memcpy(buffer->buffer + buffer->end, in_buf, first_write);
memcpy(buffer->buffer, (const uint8_t*)in_buf + first_write, rest_write);
buffer->end = (buffer->end + size) % buffer->size;
}
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size)
{
size_t first_read = size;
size_t rest_read = 0;
if (buffer->first + size > buffer->size)
{
first_read = buffer->size - buffer->first;
rest_read = size - 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);
buffer->first = (buffer->first + size) % buffer->size;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,142 +1,142 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (memory_stream.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <streams/memory_stream.h>
static uint8_t* g_buffer = NULL;
static size_t g_size = 0;
static size_t last_file_size = 0;
struct memstream
{
uint8_t *m_buf;
size_t m_size;
size_t m_ptr;
};
void memstream_set_buffer(uint8_t *buffer, size_t size)
{
g_buffer = buffer;
g_size = size;
}
size_t memstream_get_last_size(void)
{
return last_file_size;
}
static void memstream_init(memstream_t *stream, uint8_t *buffer, size_t max_size)
{
stream->m_buf = buffer;
stream->m_size = max_size;
stream->m_ptr = 0;
}
memstream_t *memstream_open(void)
{
memstream_t *stream;
if (!g_buffer || !g_size)
return NULL;
stream = (memstream_t*)calloc(1, sizeof(*stream));
memstream_init(stream, g_buffer, g_size);
g_buffer = NULL;
g_size = 0;
return stream;
}
void memstream_close(memstream_t *stream)
{
last_file_size = stream->m_ptr;
free(stream);
}
size_t memstream_read(memstream_t *stream, void *data, size_t bytes)
{
size_t avail = stream->m_size - stream->m_ptr;
if (bytes > avail)
bytes = avail;
memcpy(data, stream->m_buf + stream->m_ptr, bytes);
stream->m_ptr += bytes;
return bytes;
}
size_t memstream_write(memstream_t *stream, const void *data, size_t bytes)
{
size_t avail = stream->m_size - stream->m_ptr;
if (bytes > avail)
bytes = avail;
memcpy(stream->m_buf + stream->m_ptr, data, bytes);
stream->m_ptr += bytes;
return bytes;
}
int memstream_seek(memstream_t *stream, int offset, int whence)
{
size_t ptr;
switch (whence)
{
case SEEK_SET:
ptr = offset;
break;
case SEEK_CUR:
ptr = stream->m_ptr + offset;
break;
case SEEK_END:
ptr = stream->m_size + offset;
break;
default:
return -1;
}
if (ptr <= stream->m_size)
{
stream->m_ptr = ptr;
return 0;
}
return -1;
}
size_t memstream_pos(memstream_t *stream)
{
return stream->m_ptr;
}
char *memstream_gets(memstream_t *stream, char *buffer, size_t len)
{
return NULL;
}
int memstream_getc(memstream_t *stream)
{
if (stream->m_ptr >= stream->m_size)
return EOF;
return stream->m_buf[stream->m_ptr++];
}
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (memory_stream.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <streams/memory_stream.h>
static uint8_t* g_buffer = NULL;
static size_t g_size = 0;
static size_t last_file_size = 0;
struct memstream
{
uint8_t *m_buf;
size_t m_size;
size_t m_ptr;
};
void memstream_set_buffer(uint8_t *buffer, size_t size)
{
g_buffer = buffer;
g_size = size;
}
size_t memstream_get_last_size(void)
{
return last_file_size;
}
static void memstream_init(memstream_t *stream, uint8_t *buffer, size_t max_size)
{
stream->m_buf = buffer;
stream->m_size = max_size;
stream->m_ptr = 0;
}
memstream_t *memstream_open(void)
{
memstream_t *stream;
if (!g_buffer || !g_size)
return NULL;
stream = (memstream_t*)calloc(1, sizeof(*stream));
memstream_init(stream, g_buffer, g_size);
g_buffer = NULL;
g_size = 0;
return stream;
}
void memstream_close(memstream_t *stream)
{
last_file_size = stream->m_ptr;
free(stream);
}
size_t memstream_read(memstream_t *stream, void *data, size_t bytes)
{
size_t avail = stream->m_size - stream->m_ptr;
if (bytes > avail)
bytes = avail;
memcpy(data, stream->m_buf + stream->m_ptr, bytes);
stream->m_ptr += bytes;
return bytes;
}
size_t memstream_write(memstream_t *stream, const void *data, size_t bytes)
{
size_t avail = stream->m_size - stream->m_ptr;
if (bytes > avail)
bytes = avail;
memcpy(stream->m_buf + stream->m_ptr, data, bytes);
stream->m_ptr += bytes;
return bytes;
}
int memstream_seek(memstream_t *stream, int offset, int whence)
{
size_t ptr;
switch (whence)
{
case SEEK_SET:
ptr = offset;
break;
case SEEK_CUR:
ptr = stream->m_ptr + offset;
break;
case SEEK_END:
ptr = stream->m_size + offset;
break;
default:
return -1;
}
if (ptr <= stream->m_size)
{
stream->m_ptr = ptr;
return 0;
}
return -1;
}
size_t memstream_pos(memstream_t *stream)
{
return stream->m_ptr;
}
char *memstream_gets(memstream_t *stream, char *buffer, size_t len)
{
return NULL;
}
int memstream_getc(memstream_t *stream)
{
if (stream->m_ptr >= stream->m_size)
return EOF;
return stream->m_buf[stream->m_ptr++];
}