From: Philippe Proulx Date: Mon, 8 May 2017 23:40:27 +0000 (-0400) Subject: bt_common_shell_quote(): accept new parameter `with_single_quotes` X-Git-Tag: v2.0.0-pre1~305 X-Git-Url: https://git.efficios.com/?a=commitdiff_plain;h=36b405c633c7ea0ca02cebea0e1189b14f9245a3;hp=a8101b9166f96a7343965b6af219a848752869bd;p=babeltrace.git bt_common_shell_quote(): accept new parameter `with_single_quotes` This parameter indicates if the function must put the initial and final `'` character itself or if it's the caller's job. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/common/common.c b/common/common.c index 8d202ea5..a987e83e 100644 --- a/common/common.c +++ b/common/common.c @@ -398,7 +398,7 @@ end: } BT_HIDDEN -GString *bt_common_shell_quote(const char *input) +GString *bt_common_shell_quote(const char *input, bool with_single_quotes) { GString *output = g_string_new(NULL); const char *ch; @@ -409,7 +409,10 @@ GString *bt_common_shell_quote(const char *input) } if (strlen(input) == 0) { - g_string_assign(output, "''"); + if (with_single_quotes) { + g_string_assign(output, "''"); + } + goto end; } @@ -430,7 +433,9 @@ GString *bt_common_shell_quote(const char *input) goto end; } - g_string_assign(output, "'"); + if (with_single_quotes) { + g_string_assign(output, "'"); + } for (ch = input; *ch != '\0'; ch++) { if (*ch == '\'') { @@ -440,7 +445,9 @@ GString *bt_common_shell_quote(const char *input) } } - g_string_append_c(output, '\''); + if (with_single_quotes) { + g_string_append_c(output, '\''); + } end: return output; diff --git a/include/babeltrace/common-internal.h b/include/babeltrace/common-internal.h index b65a9d0c..13c4b79a 100644 --- a/include/babeltrace/common-internal.h +++ b/include/babeltrace/common-internal.h @@ -106,7 +106,7 @@ GString *bt_common_string_until(const char *input, const char *escapable_chars, const char *end_chars, size_t *end_pos); BT_HIDDEN -GString *bt_common_shell_quote(const char *input); +GString *bt_common_shell_quote(const char *input, bool with_single_quotes); BT_HIDDEN bool bt_common_string_is_printable(const char *input);