Commit 72dc0db2 authored by tourettes's avatar tourettes Committed by Petri Hintukainen

Changed disc_read_file method's return type to size_t

Failed read is indicated with zero return value
parent 760a5fc0
......@@ -153,11 +153,11 @@ META_ROOT *meta_parse(BD_DISC *disc)
uint8_t i;
for (i = 0; i < root->dl_count; i++) {
uint8_t *data = NULL;
int64_t size = 0;
size_t size;
size = disc_read_file(disc, "BDMV" DIR_SEP "META" DIR_SEP "DL",
root->dl_entries[i].filename,
&data);
if (!data) {
if (!data || size == 0) {
BD_DEBUG(DBG_DIR, "Failed to read BDMV/META/DL/%s\n", root->dl_entries[i].filename);
} else {
doc = xmlReadMemory((char*)data, (int)size, NULL, NULL, 0);
......
......@@ -1934,8 +1934,8 @@ static int _preload_textst_subpath(BLURAY *bd)
for (ii = 0; ii < bd->st_textst.clip->cl->font_info.font_count; ii++) {
char *file = str_printf("%s.otf", bd->st_textst.clip->cl->font_info.font[ii].file_id);
uint8_t *data = NULL;
int64_t size = disc_read_file(bd->disc, "BDMV" DIR_SEP "AUXDATA", file, &data);
if (data && gc_add_font(bd->graphics_controller, data, size) < 0) {
size_t size = disc_read_file(bd->disc, "BDMV" DIR_SEP "AUXDATA", file, &data);
if (data && size > 0 && gc_add_font(bd->graphics_controller, data, size) < 0) {
X_FREE(data);
}
X_FREE(file);
......
......@@ -350,7 +350,7 @@ BD_DIR_H *disc_open_dir(BD_DISC *p, const char *dir)
return _combine_dirs(dp_ovl, dp_rom);
}
int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
size_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
uint8_t **data)
{
BD_FILE_H *fp;
......@@ -360,26 +360,29 @@ int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
fp = disc_open_file(disc, dir, file);
if (!fp) {
return -1;
return 0;
}
size = file_size(fp);
if (size > 0) {
*data = malloc(size);
if (size > 0 && size < BD_MAX_SSIZE) {
*data = malloc((size_t)size);
if (*data) {
int64_t got = file_read(fp, *data, size);
if (got != size) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "Error reading file %s from %s\n", file, dir);
X_FREE(*data);
size = -1;
size = 0;
}
} else {
size = -1;
size = 0;
}
}
else {
size = 0;
}
file_close(fp);
return size;
return (size_t)size;
}
/*
......
......@@ -57,7 +57,7 @@ BD_PRIVATE struct bd_file_s *disc_open_path(BD_DISC *disc, const char *path);
BD_PRIVATE struct bd_dir_s *disc_open_dir (BD_DISC *disc, const char *dir);
/* Read VFS file */
BD_PRIVATE int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
BD_PRIVATE size_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
uint8_t **data);
/* Update virtual package */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment