summaryrefslogtreecommitdiff
path: root/mysys/mf_iocache2.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/mf_iocache2.c')
-rw-r--r--mysys/mf_iocache2.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c
index 6c7cd9a7e84..72372ae6bc0 100644
--- a/mysys/mf_iocache2.c
+++ b/mysys/mf_iocache2.c
@@ -287,6 +287,40 @@ my_off_t my_b_filelength(IO_CACHE *info)
}
+size_t
+my_b_write_backtick_quote(IO_CACHE *info, const char *str, size_t len)
+{
+ const uchar *start;
+ const uchar *p= (const uchar *)str;
+ const uchar *end= p + len;
+ size_t count;
+ size_t total= 0;
+
+ if (my_b_write(info, (uchar *)"`", 1))
+ return (size_t)-1;
+ ++total;
+ for (;;)
+ {
+ start= p;
+ while (p < end && *p != '`')
+ ++p;
+ count= p - start;
+ if (count && my_b_write(info, start, count))
+ return (size_t)-1;
+ total+= count;
+ if (p >= end)
+ break;
+ if (my_b_write(info, (uchar *)"``", 2))
+ return (size_t)-1;
+ total+= 2;
+ ++p;
+ }
+ if (my_b_write(info, (uchar *)"`", 1))
+ return (size_t)-1;
+ ++total;
+ return total;
+}
+
/*
Simple printf version. Supports '%s', '%d', '%u', "%ld" and "%lu"
Used for logging in MySQL
@@ -311,6 +345,7 @@ size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
uint minimum_width_sign;
uint precision; /* as yet unimplemented for anything but %b */
my_bool is_zero_padded;
+ my_bool backtick_quoting;
/*
Store the location of the beginning of a format directive, for the
@@ -345,6 +380,7 @@ size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
fmt++;
is_zero_padded= FALSE;
+ backtick_quoting= FALSE;
minimum_width_sign= 1;
minimum_width= 0;
precision= 0;
@@ -357,6 +393,8 @@ process_flags:
minimum_width_sign= -1; fmt++; goto process_flags;
case '0':
is_zero_padded= TRUE; fmt++; goto process_flags;
+ case '`':
+ backtick_quoting= TRUE; fmt++; goto process_flags;
case '#':
/** @todo Implement "#" conversion flag. */ fmt++; goto process_flags;
case ' ':
@@ -400,9 +438,19 @@ process_flags:
reg2 char *par = va_arg(args, char *);
size_t length2 = strlen(par);
/* TODO: implement precision */
- out_length+= length2;
- if (my_b_write(info, (uchar*) par, length2))
- goto err;
+ if (backtick_quoting)
+ {
+ size_t total= my_b_write_backtick_quote(info, (uchar *) par, length2);
+ if (total == (size_t)-1)
+ goto err;
+ out_length+= total;
+ }
+ else
+ {
+ out_length+= length2;
+ if (my_b_write(info, (uchar*) par, length2))
+ goto err;
+ }
}
else if (*fmt == 'b') /* Sized buffer parameter, only precision makes sense */
{