From 78f6f29c3a61c9891f66292f95817e3e018f9f5f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 12 Jun 2015 18:20:34 +0200 Subject: [PATCH] (database_info.c) Refactor some code --- database_info.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/database_info.c b/database_info.c index cf79d6d2f4..9106acab3a 100644 --- a/database_info.c +++ b/database_info.c @@ -78,13 +78,33 @@ #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); +} + int database_info_build_query(char *s, size_t len, const char *label, const char *path) { uint32_t value = 0; bool add_quotes = true; - strlcpy(s, "{'", len); + database_info_build_query_add_bracket_open(s, len); value = djb2_calculate(label); @@ -152,13 +172,13 @@ int database_info_build_query(char *s, size_t len, break; } - strlcat(s, "':", len); + database_info_build_query_add_colon(s, len); if (add_quotes) - strlcat(s, "\"", len); + database_info_build_query_add_quote(s, len); strlcat(s, path, len); if (add_quotes) - strlcat(s, "\"", len); - strlcat(s, "}", len); + database_info_build_query_add_quote(s, len); + database_info_build_query_add_bracket_close(s, len); return 0; }