diff --git a/database_info.c b/database_info.c index 63d46b72b2..2cf4385b61 100644 --- a/database_info.c +++ b/database_info.c @@ -61,36 +61,6 @@ #define DB_CURSOR_SIZE 0x7c9dede0U #define DB_CURSOR_SERIAL 0x1b843ec5U -static void database_info_build_query_add_quote(char *s, size_t len) -{ - strlcat(s, "\"", len); -} - -static void database_info_build_query_add_bracket_open(char *s, size_t len) -{ - strlcat(s, "{'", len); -} - -static void database_info_build_query_add_bracket_close(char *s, size_t len) -{ - strlcat(s, "}", len); -} - -static void database_info_build_query_add_colon(char *s, size_t len) -{ - strlcat(s, "':", len); -} - -static void database_info_build_query_add_glob_open(char *s, size_t len) -{ - strlcat(s, "glob('*", len); -} - -static void database_info_build_query_add_glob_close(char *s, size_t len) -{ - strlcat(s, "*')", len); -} - int database_info_build_query_enum(char *s, size_t len, enum database_query_type type, const char *path) @@ -98,7 +68,8 @@ int database_info_build_query_enum(char *s, size_t len, bool add_quotes = true; bool add_glob = false; - database_info_build_query_add_bracket_open(s, len); + string_add_bracket_open(s, len); + string_add_single_quote(s, len); switch (type) { @@ -169,17 +140,19 @@ int database_info_build_query_enum(char *s, size_t len, break; } - database_info_build_query_add_colon(s, len); + string_add_single_quote(s, len); + string_add_colon(s, len); if (add_glob) - database_info_build_query_add_glob_open(s, len); + string_add_glob_open(s, len); if (add_quotes) - database_info_build_query_add_quote(s, len); + string_add_quote(s, len); strlcat(s, path, len); if (add_glob) - database_info_build_query_add_glob_close(s, len); + string_add_glob_close(s, len); if (add_quotes) - database_info_build_query_add_quote(s, len); - database_info_build_query_add_bracket_close(s, len); + string_add_quote(s, len); + + string_add_bracket_close(s, len); #if 0 RARCH_LOG("query: %s\n", s); diff --git a/libretro-common/include/string/stdstring.h b/libretro-common/include/string/stdstring.h index d01e6fb175..23bf0620b7 100644 --- a/libretro-common/include/string/stdstring.h +++ b/libretro-common/include/string/stdstring.h @@ -31,6 +31,7 @@ #include #include +#include RETRO_BEGIN_DECLS @@ -53,6 +54,24 @@ static INLINE bool string_is_not_equal(const char *a, const char *b) return !string_is_equal(a, b); } +#define string_add_pair_open(s, size) strlcat((s), " (", (size)) +#define string_add_pair_close(s, size) strlcat((s), ")", (size)) +#define string_add_bracket_open(s, size) strlcat((s), "{", (size)) +#define string_add_bracket_close(s, size) strlcat((s), "}", (size)) +#define string_add_single_quote(s, size) strlcat((s), "'", (size)) +#define string_add_quote(s, size) strlcat((s), "\"", (size)) +#define string_add_colon(s, size) strlcat((s), ":", (size)) +#define string_add_glob_open(s, size) strlcat((s), "glob('*", (size)) +#define string_add_glob_close(s, size) strlcat((s), "*')", (size)) + +static INLINE void string_add_between_pairs(char *s, const char *str, + size_t size) +{ + string_add_pair_open(s, size); + strlcat(s, str, size); + string_add_pair_close(s, size); +} + #define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0) #define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 9eec6dde4f..45141fc0af 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -3136,11 +3136,8 @@ void netplay_refresh_rooms_menu(file_list_t *list) char country[PATH_MAX_LENGTH] = {0}; if (*netplay_room_list[i].country) - { - strlcat(country, " (", sizeof(country)); - strlcat(country, netplay_room_list[i].country, sizeof(country)); - strlcat(country, ")", sizeof(country)); - } + string_add_between_pairs(country, netplay_room_list[i].country, + sizeof(country)); /* Uncomment this to debug mismatched room parameters*/ #if 0