This commit is contained in:
twinaphex 2015-09-05 19:51:55 +02:00
parent e1c1917ed5
commit 728d841047
6 changed files with 37 additions and 71 deletions

View File

@ -16,13 +16,13 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <boolean.h>
#include <string.h> #include <string.h>
#include <boolean.h>
#include <rthreads/rthreads.h> #include <rthreads/rthreads.h>
#include "general.h" #include "general.h"
#include "autosave.h"
struct autosave struct autosave
{ {

View File

@ -17,14 +17,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#ifdef NEED_DYNAMIC
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#endif
#include <boolean.h> #include <boolean.h>
#include <file/file_path.h> #include <file/file_path.h>
#include <retro_log.h> #include <retro_log.h>
@ -35,13 +27,11 @@
#include "config.h" #include "config.h"
#endif #endif
#include "dynamic.h"
#include "performance.h" #include "performance.h"
#include "libretro_private.h" #include "libretro_private.h"
#include "cores/internal_cores.h" #include "cores/internal_cores.h"
#include "retroarch.h" #include "retroarch.h"
#include "runloop.h"
#include "configuration.h" #include "configuration.h"
#include "general.h" #include "general.h"
#include "msg_hash.h" #include "msg_hash.h"

View File

@ -101,26 +101,27 @@ int libretrodb_create(FILE *fp, libretrodb_value_provider value_provider,
while ((rv = value_provider(ctx, &item)) == 0) while ((rv = value_provider(ctx, &item)) == 0)
{ {
if ((rv = validate_document(&item)) < 0) if ((rv = validate_document(&item)) < 0)
goto clean; goto error;
if ((rv = rmsgpack_dom_write(fp, &item)) < 0) if ((rv = rmsgpack_dom_write(fp, &item)) < 0)
goto clean; goto error;
item_count++; item_count++;
} }
if (rv < 0) if (rv < 0)
goto clean; goto error;
if ((rv = rmsgpack_dom_write(fp, &sentinal)) < 0) if ((rv = rmsgpack_dom_write(fp, &sentinal)) < 0)
goto clean; goto error;
header.metadata_offset = httobe64(flseek(fp, 0, SEEK_CUR)); header.metadata_offset = httobe64(flseek(fp, 0, SEEK_CUR));
md.count = item_count; md.count = item_count;
libretrodb_write_metadata(fp, &md); libretrodb_write_metadata(fp, &md);
flseek(fp, root, SEEK_SET); flseek(fp, root, SEEK_SET);
fwrite(&header, 1, sizeof(header), fp); fwrite(&header, 1, sizeof(header), fp);
clean:
error:
rmsgpack_dom_value_free(&item); rmsgpack_dom_value_free(&item);
return rv; return rv;
} }
@ -405,7 +406,6 @@ static uint64_t libretrodb_tell(libretrodb_t *db)
int libretrodb_create_index(libretrodb_t *db, int libretrodb_create_index(libretrodb_t *db,
const char *name, const char *field_name) const char *name, const char *field_name)
{ {
int rv;
struct node_iter_ctx nictx; struct node_iter_ctx nictx;
struct rmsgpack_dom_value key; struct rmsgpack_dom_value key;
libretrodb_index_t idx; libretrodb_index_t idx;
@ -422,10 +422,7 @@ int libretrodb_create_index(libretrodb_t *db,
bintree_new(&tree, node_compare, &field_size); bintree_new(&tree, node_compare, &field_size);
if (libretrodb_cursor_open(db, &cur, NULL) != 0) if (libretrodb_cursor_open(db, &cur, NULL) != 0)
{ goto error;
rv = -1;
goto clean;
}
key.type = RDT_STRING; key.type = RDT_STRING;
key.val.string.len = strlen(field_name); key.val.string.len = strlen(field_name);
@ -437,49 +434,41 @@ int libretrodb_create_index(libretrodb_t *db,
{ {
if (item.type != RDT_MAP) if (item.type != RDT_MAP)
{ {
rv = -EINVAL;
printf("Only map keys are supported\n"); printf("Only map keys are supported\n");
goto clean; goto error;
} }
field = rmsgpack_dom_value_map_value(&item, &key); field = rmsgpack_dom_value_map_value(&item, &key);
if (!field) if (!field)
{ {
rv = -EINVAL;
printf("field not found in item\n"); printf("field not found in item\n");
goto clean; goto error;
} }
if (field->type != RDT_BINARY) if (field->type != RDT_BINARY)
{ {
rv = -EINVAL;
printf("field is not binary\n"); printf("field is not binary\n");
goto clean; goto error;
} }
if (field->val.binary.len == 0) if (field->val.binary.len == 0)
{ {
rv = -EINVAL;
printf("field is empty\n"); printf("field is empty\n");
goto clean; goto error;
} }
if (field_size == 0) if (field_size == 0)
field_size = field->val.binary.len; field_size = field->val.binary.len;
else if (field->val.binary.len != field_size) else if (field->val.binary.len != field_size)
{ {
rv = -EINVAL;
printf("field is not of correct size\n"); printf("field is not of correct size\n");
goto clean; goto error;
} }
buff = malloc(field_size + sizeof(uint64_t)); buff = malloc(field_size + sizeof(uint64_t));
if (!buff) if (!buff)
{ goto error;
rv = -ENOMEM;
goto clean;
}
memcpy(buff, field->val.binary.buff, field_size); memcpy(buff, field->val.binary.buff, field_size);
@ -492,18 +481,15 @@ int libretrodb_create_index(libretrodb_t *db,
printf("Value is not unique: "); printf("Value is not unique: ");
rmsgpack_dom_value_print(field); rmsgpack_dom_value_print(field);
printf("\n"); printf("\n");
rv = -EINVAL; goto error;
goto clean;
} }
buff = NULL; buff = NULL;
rmsgpack_dom_value_free(&item); rmsgpack_dom_value_free(&item);
item_loc = libretrodb_tell(db); item_loc = libretrodb_tell(db);
} }
(void)rv;
(void)idx_header_offset;
idx_header_offset = flseek(db->fp, 0, SEEK_END); idx_header_offset = flseek(db->fp, 0, SEEK_END);
(void)idx_header_offset;
strncpy(idx.name, name, 50); strncpy(idx.name, name, 50);
idx.name[49] = '\0'; idx.name[49] = '\0';
@ -515,7 +501,8 @@ int libretrodb_create_index(libretrodb_t *db,
nictx.idx = &idx; nictx.idx = &idx;
bintree_iterate(&tree, node_iter, &nictx); bintree_iterate(&tree, node_iter, &nictx);
bintree_free(&tree); bintree_free(&tree);
clean:
error:
rmsgpack_dom_value_free(&item); rmsgpack_dom_value_free(&item);
if (buff) if (buff)
free(buff); free(buff);

View File

@ -57,8 +57,7 @@ static const uint8_t MPF_NIL = 0xc0;
static INLINE ssize_t fpwrite(FILE *fp, const void *buf, size_t count) static INLINE ssize_t fpwrite(FILE *fp, const void *buf, size_t count)
{ {
size_t num_written = fwrite(buf, 1, count, fp); return (fwrite(buf, 1, count, fp) != count) ? -1 : (ssize_t)count;
return num_written != count ? -1 : (ssize_t)count;
} }
static INLINE ssize_t fpread(FILE *fp, void *buf, size_t count) static INLINE ssize_t fpread(FILE *fp, void *buf, size_t count)
@ -367,7 +366,6 @@ static int read_uint(FILE *fp, uint64_t *out, size_t size)
static int read_int(FILE *fp, int64_t *out, size_t size) static int read_int(FILE *fp, int64_t *out, size_t size)
{ {
uint8_t tmp8 = 0;
uint16_t tmp16; uint16_t tmp16;
uint32_t tmp32; uint32_t tmp32;
uint64_t tmp64; uint64_t tmp64;
@ -375,8 +373,6 @@ static int read_int(FILE *fp, int64_t *out, size_t size)
if (fpread(fp, &tmp64, size) == -1) if (fpread(fp, &tmp64, size) == -1)
return -errno; return -errno;
(void)tmp8;
switch (size) switch (size)
{ {
case 1: case 1:
@ -395,6 +391,7 @@ static int read_int(FILE *fp, int64_t *out, size_t size)
*out = *((int64_t *)(&tmp64)); *out = *((int64_t *)(&tmp64));
break; break;
} }
return 0; return 0;
} }
@ -403,18 +400,21 @@ static int read_buff(FILE *fp, size_t size, char **pbuff, uint64_t *len)
uint64_t tmp_len = 0; uint64_t tmp_len = 0;
if (read_uint(fp, &tmp_len, size) == -1) if (read_uint(fp, &tmp_len, size) == -1)
return -errno; goto error;
*pbuff = (char *)calloc((size_t)tmp_len + 1, sizeof(char)); *pbuff = (char *)calloc((size_t)tmp_len + 1, sizeof(char));
if (fpread(fp, *pbuff, (size_t)tmp_len) == -1) if (fpread(fp, *pbuff, (size_t)tmp_len) == -1)
{ goto error;
free(*pbuff);
return -errno;
}
*len = tmp_len; *len = tmp_len;
return 0; return 0;
error:
if (*pbuff)
free(*pbuff);
return -errno;
} }
static int read_map(FILE *fp, uint32_t len, static int read_map(FILE *fp, uint32_t len,

View File

@ -354,8 +354,7 @@ void rmsgpack_dom_value_print(struct rmsgpack_dom_value *obj)
break; break;
case RDT_STRING: case RDT_STRING:
printf("\"%s\"", obj->val.string.buff); printf("\"%s\"", obj->val.string.buff);
break; break; case RDT_BINARY:
case RDT_BINARY:
printf("\""); printf("\"");
for (i = 0; i < obj->val.binary.len; i++) for (i = 0; i < obj->val.binary.len; i++)
printf("%02X", (unsigned char) obj->val.binary.buff[i]); printf("%02X", (unsigned char) obj->val.binary.buff[i]);
@ -462,14 +461,11 @@ int rmsgpack_dom_read_into(FILE *fp, ...)
uint64_t min_len; uint64_t min_len;
char *buff_value = NULL; char *buff_value = NULL;
const char *key_name = NULL; const char *key_name = NULL;
int value_type = 0;
va_start(ap, fp); va_start(ap, fp);
rv = rmsgpack_dom_read(fp, &map); rv = rmsgpack_dom_read(fp, &map);
(void)value_type;
if (rv < 0) if (rv < 0)
{ {
va_end(ap); va_end(ap);
@ -477,20 +473,14 @@ int rmsgpack_dom_read_into(FILE *fp, ...)
} }
if (map.type != RDT_MAP) if (map.type != RDT_MAP)
{ goto error;
rv = -EINVAL;
goto clean;
}
while (1) while (1)
{ {
key_name = va_arg(ap, const char *); key_name = va_arg(ap, const char *);
if (!key_name) if (!key_name)
{ goto error;
rv = 0;
goto clean;
}
key.type = RDT_STRING; key.type = RDT_STRING;
key.val.string.len = strlen(key_name); key.val.string.len = strlen(key_name);
@ -531,12 +521,11 @@ int rmsgpack_dom_read_into(FILE *fp, ...)
memcpy(buff_value, value->val.string.buff, (size_t)min_len); memcpy(buff_value, value->val.string.buff, (size_t)min_len);
break; break;
default: default:
rv = -1; goto error;
goto clean;
} }
} }
clean: error:
va_end(ap); va_end(ap);
rmsgpack_dom_value_free(&map); rmsgpack_dom_value_free(&map);
return 0; return 0;

View File

@ -14,13 +14,13 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "movie.h"
#include <rhash.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <rhash.h>
#include "general.h" #include "general.h"
#include "dynamic.h"
struct bsv_movie struct bsv_movie
{ {