diff options
Diffstat (limited to 'innobase/ut')
-rw-r--r-- | innobase/ut/ut0byte.c | 44 | ||||
-rw-r--r-- | innobase/ut/ut0mem.c | 49 |
2 files changed, 69 insertions, 24 deletions
diff --git a/innobase/ut/ut0byte.c b/innobase/ut/ut0byte.c index 02bdf2065ee..4ec7e0f405e 100644 --- a/innobase/ut/ut0byte.c +++ b/innobase/ut/ut0byte.c @@ -36,9 +36,9 @@ Copies a string to a memory location, setting characters to lower case. */ void ut_cpy_in_lower_case( /*=================*/ - char* dest, /* in: destination */ - char* source,/* in: source */ - ulint len) /* in: string length */ + char* dest, /* in: destination */ + const char* source, /* in: source */ + ulint len) /* in: string length */ { ulint i; @@ -53,23 +53,27 @@ Compares two strings when converted to lower case. */ int ut_cmp_in_lower_case( /*=================*/ - /* out: -1, 0, 1 if str1 < str2, str1 == str2, - str1 > str2, respectively */ - char* str1, /* in: string1 */ - char* str2, /* in: string2 */ - ulint len) /* in: length of both strings */ + /* out: -1, 0, 1 if str1 < str2, str1 == str2, + str1 > str2, respectively */ + const char* str1, /* in: string1 */ + const char* str2) /* in: string2 */ { - ulint i; - - for (i = 0; i < len; i++) { - if (tolower(str1[i]) < tolower(str2[i])) { - return(-1); - } - - if (tolower(str1[i]) > tolower(str2[i])) { - return(1); - } - } + for (;;) { + int c1, c2; + if (!*str1) { + return(*str2 ? -1 : 0); + } else if (!*str2) { + return 1; + } + c1 = tolower(*str1++); + c2 = tolower(*str2++); + if (c1 < c2) { + return(-1); + } + if (c1 > c2) { + return(1); + } + } - return(0); + return(0); } diff --git a/innobase/ut/ut0mem.c b/innobase/ut/ut0mem.c index f5d207d8bba..1fcaf9febbe 100644 --- a/innobase/ut/ut0mem.c +++ b/innobase/ut/ut0mem.c @@ -106,7 +106,7 @@ ut_malloc_low( /* Make an intentional seg fault so that we get a stack trace */ - printf("%lu\n", *ut_mem_null_ptr); + if (*ut_mem_null_ptr) ut_mem_null_ptr = 0; } if (set_to_zero) { @@ -195,6 +195,49 @@ ut_free_all_mem(void) } /************************************************************************** +Make a quoted copy of a string. */ + +char* +ut_strcpyq( +/*=======*/ + /* out: pointer to end of dest */ + char* dest, /* in: output buffer */ + char q, /* in: the quote character */ + const char* src) /* in: null-terminated string */ +{ + while (*src) { + if ((*dest++ = *src++) == q) { + *dest++ = q; + } + } + + return(dest); +} + +/************************************************************************** +Make a quoted copy of a fixed-length string. */ + +char* +ut_memcpyq( +/*=======*/ + /* out: pointer to end of dest */ + char* dest, /* in: output buffer */ + char q, /* in: the quote character */ + const char* src, /* in: string to be quoted */ + ulint len) /* in: length of src */ +{ + const char* srcend = src + len; + + while (src < srcend) { + if ((*dest++ = *src++) == q) { + *dest++ = q; + } + } + + return(dest); +} + +/************************************************************************** Catenates two strings into newly allocated memory. The memory must be freed using mem_free. */ @@ -215,9 +258,7 @@ ut_str_catenate( str = mem_alloc(len1 + len2 + 1); ut_memcpy(str, str1, len1); - ut_memcpy(str + len1, str2, len2); - - str[len1 + len2] = '\0'; + ut_memcpy(str + len1, str2, len2 + 1); return(str); } |