diff --git a/Makefile b/Makefile index 6d1f50535f..1ac36639ca 100644 --- a/Makefile +++ b/Makefile @@ -397,6 +397,7 @@ clean: rm -f record/*.o rm -f input/*.o rm -f tools/*.o + rm -f tools/retrolaunch/*.o rm -f $(TARGET) .PHONY: all install uninstall clean diff --git a/file.h b/file.h index 47fdb13ddf..dac862eb0d 100644 --- a/file.h +++ b/file.h @@ -24,6 +24,10 @@ #include #include "general.h" +#ifdef __cplusplus +extern "C" { +#endif + // Generic file, path and directory handling. ssize_t read_file(const char *path, void **buf); @@ -127,4 +131,8 @@ void fill_pathname_join(char *out_path, const char *dir, const char *path, size_ size_t convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size); size_t convert_wchar_to_char(char *out_char, const wchar_t *in_wchar, size_t size); +#ifdef __cplusplus +} +#endif + #endif diff --git a/retroarch.c b/retroarch.c index 24ce3aa066..4a1514b71b 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2956,7 +2956,7 @@ int rarch_main_init_wrap(const struct rarch_main_wrap *args) int ret = rarch_main_init(argc, argv); - for (int i = 0; i < ARRAY_SIZE(argv_copy); i++) + for (unsigned i = 0; i < ARRAY_SIZE(argv_copy); i++) free(argv_copy[i]); return ret; diff --git a/tools/retrolaunch/cd_detect.c b/tools/retrolaunch/cd_detect.c index 37f5f8c993..7bfda5dab3 100644 --- a/tools/retrolaunch/cd_detect.c +++ b/tools/retrolaunch/cd_detect.c @@ -15,8 +15,8 @@ #define MAGIC_LEN 16 struct MagicEntry { - char* system_name; - char* magic; + const char* system_name; + const char* magic; }; static struct MagicEntry MAGIC_NUMBERS[] = { @@ -121,7 +121,8 @@ static int detect_ps1_game(const char* track_path, int32_t offset, char* game_name, size_t max_len) { int rv; char buff[4096]; - char* pattern = "cdrom:"; + const char* pattern = "cdrom:"; + const char* pat_c; char* c; char* id_start; int i; @@ -141,7 +142,8 @@ static int detect_ps1_game(const char* track_path, int32_t offset, goto clean; } } - c = pattern; + memset(buff, 0, sizeof(buff)); + pat_c = pattern; while (1) { rv = read(fd, buff, 4096); if (rv < 0) { @@ -149,20 +151,26 @@ static int detect_ps1_game(const char* track_path, int32_t offset, goto clean; } - for(i = 0; i < 4096; i++) { - if (*c == buff[i]) { - c++; + for (i = 0; i < rv; i++) { + if (*pat_c == buff[i]) { + pat_c++; } else { - c = pattern; + pat_c = pattern; continue; } - if (*c == '\0') { + if (*pat_c == '\0') { id_start = &buff[i] + 1; - *strchr(id_start, ';') = '\0'; - c = strrchr(id_start, '\\') + 1; + c = strchr(id_start, ';'); + if (!c) { + LOG_DEBUG("Invalid pattern in buffer."); + rv = -EINVAL; + goto clean; + } + *c = '\0'; + c = strrchr(id_start, '\\'); if (c != NULL) { - id_start = c; + id_start = c + 1; } id_start[4] = '-'; id_start[8] = id_start[9]; @@ -181,7 +189,7 @@ clean: } static int detect_system(const char* track_path, int32_t offset, - char** system_name) { + const char** system_name) { int rv; char magic[MAGIC_LEN]; int fd; @@ -272,7 +280,7 @@ int detect_cd_game(const char* target_path, char* game_name, size_t max_len) { char cue_path[PATH_MAX]; char track_path[PATH_MAX]; int32_t offset = 0; - char* system_name = NULL; + const char* system_name = NULL; int rv; if (strcasecmp(target_path + strlen(target_path) - 4, ".m3u") == 0) { rv = find_fist_cue(target_path, cue_path, PATH_MAX); diff --git a/tools/retrolaunch/main.c b/tools/retrolaunch/main.c index fb1e9e131f..877cb7c629 100644 --- a/tools/retrolaunch/main.c +++ b/tools/retrolaunch/main.c @@ -54,7 +54,7 @@ static int find_rom_canonical_name(const char *hash, char *game_name, size_t max_len) { // TODO: Error handling - int i; + size_t i; int rv; int fd; int offs; @@ -199,7 +199,7 @@ static int get_run_info(struct RunInfo *info, char *game_name) return rv; } -char *SUFFIX_MATCH[] = { +const char *SUFFIX_MATCH[] = { ".a26", "a26", ".bin", "smd", ".gba", "gba", @@ -222,8 +222,8 @@ static int detect_rom_game(const char *path, char *game_name, size_t max_len) { char hash[HASH_LEN + 1]; int rv; - char *suffix; - char **tmp_suffix; + const char *suffix; + const char **tmp_suffix; suffix = strrchr(path, '.'); if (!suffix) { @@ -270,7 +270,7 @@ static int run_retroarch(const char *path, const struct RunInfo *info) { char core_path[PATH_MAX]; sprintf(core_path, "./cores/libretro-%s.so", info->core); - char *retro_argv[30] = { "retroarch", + const char *retro_argv[30] = { "retroarch", "-L", core_path }; int argi = 3; @@ -295,7 +295,7 @@ static int run_retroarch(const char *path, const struct RunInfo *info) retro_argv[argi] = strdup(path); argi++; retro_argv[argi] = NULL; - execvp(retro_argv[0], retro_argv); + execvp(retro_argv[0], (char * const*)retro_argv); return -errno; } diff --git a/tools/retrolaunch/parser.c b/tools/retrolaunch/parser.c index b7f135db69..cf4ed90ac7 100644 --- a/tools/retrolaunch/parser.c +++ b/tools/retrolaunch/parser.c @@ -51,17 +51,20 @@ ssize_t get_token(int fd, char *token, size_t max_len) len++; c++; - if (len == max_len) { + if (len == (ssize_t)max_len) { *c = '\0'; return len; } } } -int find_token(int fd, char *token) +int find_token(int fd, const char *token) { int tmp_len = strlen(token); - char *tmp_token = calloc(tmp_len, sizeof(char)); + char *tmp_token = (char*)calloc(tmp_len, 1); + if (!tmp_token) { + return -1; + } while (strncmp(tmp_token, token, tmp_len) != 0) { if (get_token(fd, tmp_token, tmp_len) <= 0) { return -1; diff --git a/tools/retrolaunch/parser.h b/tools/retrolaunch/parser.h index 195fb3259a..9438e6771e 100644 --- a/tools/retrolaunch/parser.h +++ b/tools/retrolaunch/parser.h @@ -3,4 +3,4 @@ #define MAX_TOKEN_LEN 255 ssize_t get_token(int fd, char* token, size_t max_len); -int find_token(int fd, char* token); +int find_token(int fd, const char* token);