Remove errno dep (task_database_cue.c) (#14341)

* (task_database_cue.c) Turn some functions static - some general cleanups

* Start removing errno dependency on task_database_cue.c
This commit is contained in:
LibretroAdmin 2022-08-24 15:15:21 +02:00 committed by GitHub
parent 6b9a382f2e
commit fdc563e6f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 116 deletions

View File

@ -269,10 +269,6 @@ sizeof(track_path)) < 0)
return 0;
}
#ifdef DEBUG
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
#endif
return intfstream_file_get_serial(track_path, offset, size, serial);
}
@ -292,10 +288,6 @@ static int task_database_gdi_get_serial(const char *name, char* serial)
return 0;
}
#ifdef DEBUG
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
#endif
return intfstream_file_get_serial(track_path, 0, SIZE_MAX, serial);
}
@ -380,12 +372,11 @@ static int task_database_cue_get_crc(const char *name, uint32_t *crc)
char track_path[PATH_MAX_LENGTH];
uint64_t offset = 0;
uint64_t size = 0;
int rv = 0;
track_path[0] = '\0';
if ((rv = cue_find_track(name, false, &offset, &size,
track_path, sizeof(track_path))) < 0)
if (cue_find_track(name, false, &offset, &size,
track_path, sizeof(track_path)) < 0)
{
#ifdef DEBUG
RARCH_LOG("%s\n",
@ -394,28 +385,17 @@ static int task_database_cue_get_crc(const char *name, uint32_t *crc)
return 0;
}
#ifdef DEBUG
RARCH_LOG("CUE '%s' primary track: %s\n (%lu, %lu)\n",name, track_path, (unsigned long) offset, (unsigned long) size);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
rv = intfstream_file_get_crc(track_path, offset, (size_t)size, crc);
if (rv == 1)
RARCH_LOG("CUE '%s' crc: %x\n", name, *crc);
return rv;
#else
return intfstream_file_get_crc(track_path, offset, (size_t)size, crc);
#endif
}
static int task_database_gdi_get_crc(const char *name, uint32_t *crc)
{
char track_path[PATH_MAX_LENGTH];
int rv = 0;
track_path[0] = '\0';
if ((rv = gdi_find_track(name, true,
track_path, sizeof(track_path))) < 0)
if (gdi_find_track(name, true,
track_path, sizeof(track_path)) < 0)
{
#ifdef DEBUG
RARCH_LOG("%s\n",
@ -424,22 +404,12 @@ static int task_database_gdi_get_crc(const char *name, uint32_t *crc)
return 0;
}
#ifdef DEBUG
RARCH_LOG("GDI '%s' primary track: %s\n", name, track_path);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
rv = intfstream_file_get_crc(track_path, 0, SIZE_MAX, crc);
if (rv == 1)
RARCH_LOG("GDI '%s' crc: %x\n", name, *crc);
return rv;
#else
return intfstream_file_get_crc(track_path, 0, SIZE_MAX, crc);
#endif
}
static bool task_database_chd_get_crc(const char *name, uint32_t *crc)
{
bool rv;
bool found_crc = false;
intfstream_t *fd = intfstream_open_chd_track(
name,
RETRO_VFS_FILE_ACCESS_READ,
@ -448,17 +418,13 @@ static bool task_database_chd_get_crc(const char *name, uint32_t *crc)
if (!fd)
return 0;
rv = intfstream_get_crc(fd, crc);
#ifdef DEBUG
if (rv)
RARCH_LOG("CHD '%s' crc: %x\n", name, *crc);
#endif
found_crc = intfstream_get_crc(fd, crc);
if (fd)
{
intfstream_close(fd);
free(fd);
}
return rv;
return found_crc;
}
static void task_database_cue_prune(database_info_handle_t *db,

View File

@ -77,73 +77,55 @@ static struct magic_entry MAGIC_NUMBERS[] = {
/**
* Given a filename and position, find the associated disc number.
*/
int cue_find_disc_number(const char* str1, int index)
static int cue_find_disc_number(const char* str1, int index)
{
char disc;
int disc_number = 0;
char disc = str1[index + 6];
disc = str1[index + 6];
switch(disc)
switch (disc)
{
case 'a':
case 'A':
disc_number = 1;
break;
return 1;
case 'b':
case 'B':
disc_number = 2;
break;
return 2;
case 'c':
case 'C':
disc_number = 3;
break;
return 3;
case 'd':
case 'D':
disc_number = 4;
break;
return 4;
case 'e':
case 'E':
disc_number = 5;
break;
return 5;
case 'f':
case 'F':
disc_number = 6;
break;
return 6;
case 'g':
case 'G':
disc_number = 7;
break;
return 7;
case 'h':
case 'H':
disc_number = 8;
break;
return 8;
case 'i':
case 'I':
disc_number = 9;
break;
return 9;
default:
disc_number = disc - '0';
if ((disc - '0') >= 1)
return (disc - '0');
break;
}
if (disc_number >= 1)
return disc_number;
return 0;
}
/**
* Given a title and filename, append the appropriate disc number to it.
*/
void cue_append_multi_disc_suffix(char * str1, const char *filename)
static void cue_append_multi_disc_suffix(char * str1, const char *filename)
{
char *dest = str1;
int result = 0;
int disc_number = 0;
/** check multi-disc and insert suffix **/
result = string_find_index_substring_string(filename, "(Disc ");
/* Check multi-disc and insert suffix */
int result = string_find_index_substring_string(filename, "(Disc ");
if (result < 0)
result = string_find_index_substring_string(filename, "(disc ");
if (result < 0)
@ -152,9 +134,10 @@ void cue_append_multi_disc_suffix(char * str1, const char *filename)
result = string_find_index_substring_string(filename, "(disk ");
if (result >= 0)
{
disc_number = cue_find_disc_number(filename, result);
char *dest = str1;
int disc_number = cue_find_disc_number(filename, result);
if (disc_number > 0)
sprintf(dest+strlen(dest), "-%i", disc_number - 1);
sprintf(dest + strlen(dest), "-%i", disc_number - 1);
}
}
@ -727,10 +710,9 @@ int detect_dc_game(intfstream_t *fd, char *game_id, const char *filename)
index = string_index_last_occurance(raw_game_id, hyphen);
if (index < 0)
return false;
else
size_t_var = (size_t)index;
size_t_var = (size_t)index;
strncpy(lgame_id, &raw_game_id[0], size_t_var);
lgame_id[index] = '\0';
lgame_id[index] = '\0';
strncpy(rgame_id, &raw_game_id[index + 1], length - 1);
rgame_id[length - 1] = '\0';
strcat(game_id, lgame_id);
@ -751,7 +733,7 @@ int detect_dc_game(intfstream_t *fd, char *game_id, const char *filename)
else
{
strncpy(lgame_id, raw_game_id, 7);
lgame_id[7] = '\0';
lgame_id[7] = '\0';
strncpy(rgame_id, &raw_game_id[length - 2], length - 1);
rgame_id[length - 1] = '\0';
strcat(game_id, lgame_id);
@ -765,7 +747,7 @@ int detect_dc_game(intfstream_t *fd, char *game_id, const char *filename)
else if (!strcmp(check_prefix_t, "T"))
{
strncpy(lgame_id, raw_game_id, 1);
lgame_id[1] = '\0';
lgame_id[1] = '\0';
strncpy(rgame_id, &raw_game_id[1], length - 1);
rgame_id[length - 1] = '\0';
sprintf(pre_game_id, "%s%s%s", lgame_id, hyphen_str, rgame_id);
@ -776,11 +758,10 @@ int detect_dc_game(intfstream_t *fd, char *game_id, const char *filename)
index = string_index_last_occurance(pre_game_id, hyphen);
if (index < 0)
return false;
else
size_t_var = (size_t)index;
size_t_var = (size_t)index;
strncpy(lgame_id, pre_game_id, size_t_var);
lgame_id[index] = '\0';
length_recalc = strlen(pre_game_id);
lgame_id[index] = '\0';
length_recalc = strlen(pre_game_id);
strncpy(rgame_id, &pre_game_id[length_recalc - 2], length_recalc - 1);
rgame_id[length_recalc - 1] = '\0';
strcat(game_id, lgame_id);
@ -850,7 +831,7 @@ int detect_dc_game(intfstream_t *fd, char *game_id, const char *filename)
else
{
strncpy(lgame_id, raw_game_id, 8);
lgame_id[8] = '\0';
lgame_id[8] = '\0';
strncpy(rgame_id, &raw_game_id[length - 2], length - 1);
rgame_id[length - 1] = '\0';
strcat(game_id, lgame_id);
@ -1060,7 +1041,7 @@ int cue_find_track(const char *cue_path, bool first,
tmp_token[0] = '\0';
rv = -EINVAL;
rv = -1;
while (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0)
{
@ -1153,15 +1134,14 @@ error:
intfstream_close(fd);
free(fd);
}
return -errno;
return -1;
}
bool cue_next_file(intfstream_t *fd,
const char *cue_path, char *path, uint64_t max_len)
const char *cue_path, char *s, uint64_t len)
{
char tmp_token[MAX_TOKEN_LEN];
char cue_dir[PATH_MAX_LENGTH];
bool rv = false;
cue_dir[0] = '\0';
fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));
@ -1173,24 +1153,22 @@ bool cue_next_file(intfstream_t *fd,
if (string_is_equal_noncase(tmp_token, "FILE"))
{
task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
fill_pathname_join_special(path, cue_dir,
tmp_token, (size_t)max_len);
rv = true;
break;
fill_pathname_join_special(s, cue_dir, tmp_token, (size_t)len);
return true;
}
}
return rv;
return false;
}
int gdi_find_track(const char *gdi_path, bool first,
char *track_path, uint64_t max_len)
{
int rv;
intfstream_info_t info;
char tmp_token[MAX_TOKEN_LEN];
intfstream_t *fd = NULL;
uint64_t largest = 0;
int rv = -1;
int size = -1;
int mode = -1;
int64_t file_size = -1;
@ -1215,8 +1193,6 @@ int gdi_find_track(const char *gdi_path, bool first,
tmp_token[0] = '\0';
rv = -EINVAL;
/* Skip track count */
task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
@ -1225,35 +1201,23 @@ int gdi_find_track(const char *gdi_path, bool first,
{
/* Offset */
if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
{
errno = EINVAL;
goto error;
}
/* Mode */
if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
{
errno = EINVAL;
goto error;
}
mode = atoi(tmp_token);
/* Sector size */
if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
{
errno = EINVAL;
goto error;
}
size = atoi(tmp_token);
/* File name */
if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
{
errno = EINVAL;
goto error;
}
/* Check for data track */
if (!(mode == 0 && size == 2352))
@ -1282,10 +1246,7 @@ int gdi_find_track(const char *gdi_path, bool first,
/* Disc offset (not used?) */
if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
{
errno = EINVAL;
goto error;
}
}
clean:
@ -1299,7 +1260,7 @@ error:
intfstream_close(fd);
free(fd);
}
return -errno;
return -1;
}
bool gdi_next_file(intfstream_t *fd, const char *gdi_path,