summaryrefslogtreecommitdiff
path: root/mysys/string.c
diff options
context:
space:
mode:
authorunknown <iggy@recycle.(none)>2007-01-18 11:40:22 -0500
committerunknown <iggy@recycle.(none)>2007-01-18 11:40:22 -0500
commit4ee678f9d2e7e5a04401dd4c5e7c51b5673b8171 (patch)
treeae5dcbe86c1237e32fc759c53d5928dc41331600 /mysys/string.c
parent1a0bd37c4d5741e7297f318da07d77767a537ca7 (diff)
parentb1bfec73099b8349f07673e68d1d7ac25316dd4c (diff)
downloadmariadb-git-4ee678f9d2e7e5a04401dd4c5e7c51b5673b8171.tar.gz
Merge recycle.(none):/src/bug22807/my50-bug22807
into recycle.(none):/src/bug22807/my51-bug22807 client/mysql_upgrade.c: Auto merged include/my_sys.h: Auto merged mysys/string.c: Auto merged
Diffstat (limited to 'mysys/string.c')
-rw-r--r--mysys/string.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/mysys/string.c b/mysys/string.c
index 86de7bfcf69..dd483e6da87 100644
--- a/mysys/string.c
+++ b/mysys/string.c
@@ -121,6 +121,58 @@ my_bool dynstr_trunc(DYNAMIC_STRING *str, int n)
return FALSE;
}
+/** Concatenates any number of strings, escapes any OS quote in the result then
+ * surround the whole affair in another set of quotes which is finally appended
+ * to specified DYNAMIC_STRING. This function is especially useful when
+ * building strings to be executed with the system() function.
+ * @param str Dynamic String which will have addtional strings appended.
+ * @param append String to be appended.
+ * @param ... Optional. Additional string(s) to be appended.
+ *
+ * @note The final argument in the list must be NullS even if no additional
+ * options are passed.
+ *
+ * @return True = Success.
+ */
+my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append, ...)
+{
+#ifdef __WIN__
+ char quote_str[]= "\"";
+#else
+ char quote_str[]= "\'";
+#endif /* __WIN__ */
+ my_bool ret= TRUE;
+ va_list dirty_text;
+
+ ret&= dynstr_append(str, quote_str); /* Leading quote */
+ va_start(dirty_text,append);
+ while (append != NullS)
+ {
+ char *cur_pos= append;
+ char *next_pos= cur_pos;
+
+ /* Search for quote in each string and replace with escaped quote */
+ while(*(next_pos= strcend(cur_pos, quote_str[0])) != '\0')
+ {
+ char *tmp_buff= my_malloc((next_pos - cur_pos) + 1, MYF(MY_ZEROFILL));
+ strnmov(tmp_buff, cur_pos, (next_pos - cur_pos));
+ ret&= dynstr_append(str, tmp_buff);
+ my_free((gptr)tmp_buff, MYF(0));
+
+ ret&= dynstr_append(str ,"\\");
+ ret&= dynstr_append(str, quote_str);
+ cur_pos= next_pos + 1;
+ }
+ ret&= dynstr_append(str, cur_pos);
+ append= va_arg(dirty_text, char *);
+ }
+ va_end(dirty_text);
+ ret&= dynstr_append(str, quote_str); /* Trailing quote */
+
+ return ret;
+}
+
+
void dynstr_free(DYNAMIC_STRING *str)
{
if (str->str)