summaryrefslogtreecommitdiff
path: root/innobase/ut
diff options
context:
space:
mode:
authorunknown <monty@mishka.local>2004-04-26 15:53:31 +0300
committerunknown <monty@mishka.local>2004-04-26 15:53:31 +0300
commit1065f2bbd66ac4b1161f5c188171a54cbad5b422 (patch)
tree25e3315af05fa92d20d2ad1d812882957c400337 /innobase/ut
parent0ba6cb48d84f1ff951d09871a96be6cdef3f2c3c (diff)
parent6366a9090c7fc24f0e13b5b9d73d6777dcda9d9e (diff)
downloadmariadb-git-1065f2bbd66ac4b1161f5c188171a54cbad5b422.tar.gz
Merge with 4.0
innobase/dict/dict0boot.c: Auto merged innobase/dict/dict0load.c: Auto merged innobase/dict/dict0mem.c: Auto merged innobase/fut/fut0lst.c: Auto merged innobase/include/buf0lru.h: Auto merged innobase/include/dict0mem.h: Auto merged innobase/include/fsp0fsp.h: Auto merged innobase/include/ha0ha.h: Auto merged innobase/include/ibuf0ibuf.h: Auto merged innobase/include/lock0lock.h: Auto merged innobase/include/log0log.h: Auto merged innobase/include/mem0pool.h: Auto merged innobase/include/mtr0mtr.h: Auto merged innobase/include/os0file.h: Auto merged innobase/include/rem0rec.h: Auto merged innobase/include/rem0rec.ic: Auto merged innobase/include/srv0srv.h: Auto merged innobase/include/sync0sync.h: Auto merged innobase/include/trx0sys.h: Auto merged innobase/include/ut0byte.h: Auto merged innobase/include/ut0ut.h: Auto merged innobase/mem/mem0pool.c: Auto merged innobase/mtr/mtr0mtr.c: Auto merged innobase/os/os0proc.c: Auto merged innobase/pars/lexyy.c: Auto merged innobase/pars/pars0opt.c: Auto merged innobase/row/row0ins.c: Auto merged innobase/row/row0purge.c: Auto merged innobase/row/row0uins.c: Auto merged innobase/row/row0umod.c: Auto merged innobase/row/row0undo.c: Auto merged innobase/row/row0upd.c: Auto merged innobase/trx/trx0purge.c: Auto merged innobase/trx/trx0roll.c: Auto merged innobase/trx/trx0sys.c: Auto merged innobase/trx/trx0undo.c: Auto merged innobase/ut/ut0byte.c: Auto merged pstack/bucomm.h: Auto merged pstack/budbg.h: Auto merged sql/item_sum.h: Auto merged sql/slave.cc: Auto merged sql/sql_db.cc: Auto merged support-files/mysql.spec.sh: Auto merged tests/insert_test.c: Auto merged mysql-test/t/func_group.test: Merge with 4.0 Put 4.1 tests lasts sql/ha_innodb.cc: Merge with 4.0 Added checking of results from my_malloc() BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'innobase/ut')
-rw-r--r--innobase/ut/ut0byte.c44
-rw-r--r--innobase/ut/ut0mem.c73
-rw-r--r--innobase/ut/ut0ut.c148
3 files changed, 154 insertions, 111 deletions
diff --git a/innobase/ut/ut0byte.c b/innobase/ut/ut0byte.c
index 74198419560..8764103dc36 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 f7c0e1be9bd..9d0e63e6099 100644
--- a/innobase/ut/ut0mem.c
+++ b/innobase/ut/ut0mem.c
@@ -107,7 +107,7 @@ ut_malloc_low(
/* Make an intentional seg fault so that we get a stack
trace */
- printf("%lu\n", (ulong) *ut_mem_null_ptr);
+ if (*ut_mem_null_ptr) ut_mem_null_ptr = 0;
}
if (set_to_zero) {
@@ -232,6 +232,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. */
@@ -252,38 +295,12 @@ 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);
}
/**************************************************************************
-Checks if a null-terminated string contains a certain character. */
-
-ibool
-ut_str_contains(
-/*============*/
- char* str, /* in: null-terminated string */
- char c) /* in: character */
-{
- ulint len;
- ulint i;
-
- len = ut_strlen(str);
-
- for (i = 0; i < len; i++) {
- if (str[i] == c) {
-
- return(TRUE);
- }
- }
-
- return(FALSE);
-}
-
-/**************************************************************************
Return a copy of the given string. The returned string must be freed
using mem_free. */
diff --git a/innobase/ut/ut0ut.c b/innobase/ut/ut0ut.c
index 77f7a997777..21677e98318 100644
--- a/innobase/ut/ut0ut.c
+++ b/innobase/ut/ut0ut.c
@@ -19,6 +19,16 @@ Created 5/11/1994 Heikki Tuuri
ibool ut_always_false = FALSE;
+/*********************************************************************
+Get the quote character to be used in SQL identifiers.
+This definition must match the one in sql/ha_innodb.cc! */
+
+char
+mysql_get_identifier_quote_char(void);
+/*=================================*/
+ /* out: quote character to be
+ used in SQL identifiers */
+
/************************************************************
On the 64-bit Windows we substitute the format string
%l -> %I64
@@ -337,7 +347,7 @@ ut_print_timestamp(
}
/**************************************************************
-Sprintfs a timestamp to a buffer. */
+Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
void
ut_sprintf_timestamp(
@@ -474,7 +484,7 @@ ut_delay(
}
if (ut_always_false) {
- printf("%lu", (ulong) j);
+ ut_always_false = (ibool) j;
}
return(j);
@@ -486,78 +496,29 @@ Prints the contents of a memory buffer in hex and ascii. */
void
ut_print_buf(
/*=========*/
- byte* buf, /* in: memory buffer */
- ulint len) /* in: length of the buffer */
+ FILE* file, /* in: file where to print */
+ const byte* buf, /* in: memory buffer */
+ ulint len) /* in: length of the buffer */
{
- byte* data;
- ulint i;
+ const byte* data;
+ ulint i;
- printf(" len %lu; hex ", (ulong) len);
-
- data = buf;
+ fprintf(file, " len %lu; hex ", len);
- for (i = 0; i < len; i++) {
- printf("%02lx", (ulong) *data);
- data++;
+ for (data = buf, i = 0; i < len; i++) {
+ fprintf(file, "%02lx", (ulong)*data++);
}
- printf("; asc ");
+ fputs("; asc ", file);
data = buf;
for (i = 0; i < len; i++) {
- if (isprint((int)(*data))) {
- printf("%c", (char)*data);
- }
- data++;
+ int c = (int) *data++;
+ putc(isprint(c) ? c : ' ', file);
}
- printf(";");
-}
-
-/*****************************************************************
-Prints the contents of a memory buffer in hex and ascii. */
-
-ulint
-ut_sprintf_buf(
-/*===========*/
- /* out: printed length in bytes */
- char* str, /* in: buffer to print to */
- byte* buf, /* in: memory buffer */
- ulint len) /* in: length of the buffer */
-{
- byte* data;
- ulint n;
- ulint i;
-
- n = 0;
-
- n += sprintf(str + n, " len %lu; hex ", (ulong) len);
-
- data = buf;
-
- for (i = 0; i < len; i++) {
- n += sprintf(str + n, "%02lx", (ulong) *data);
- data++;
- }
-
- n += sprintf(str + n, "; asc ");
-
- data = buf;
-
- for (i = 0; i < len; i++) {
- if (isprint((int)(*data))) {
- n += sprintf(str + n, "%c", (char)*data);
- } else {
- n += sprintf(str + n, ".");
- }
-
- data++;
- }
-
- n += sprintf(str + n, ";");
-
- return(n);
+ putc(';', file);
}
/****************************************************************
@@ -593,3 +554,64 @@ ut_2_power_up(
return(res);
}
+
+/**************************************************************************
+Outputs a NUL-terminated string, quoted as an SQL identifier. */
+
+void
+ut_print_name(
+/*==========*/
+ FILE* f, /* in: output stream */
+ const char* name) /* in: name to print */
+{
+ ut_print_namel(f, name, strlen(name));
+}
+
+/**************************************************************************
+Outputs a fixed-length string, quoted as an SQL identifier. */
+
+void
+ut_print_namel(
+/*==========*/
+ FILE* f, /* in: output stream */
+ const char* name, /* in: name to print */
+ ulint namelen)/* in: length of name */
+{
+ const char* s = name;
+ const char* e = s + namelen;
+ char q = mysql_get_identifier_quote_char();
+ putc(q, f);
+ while (s < e) {
+ int c = *s++;
+ if (c == q) {
+ putc(c, f);
+ }
+ putc(c, f);
+ }
+ putc(q, f);
+}
+
+/**************************************************************************
+Catenate files. */
+
+void
+ut_copy_file(
+/*=========*/
+ FILE* dest, /* in: output file */
+ FILE* src) /* in: input file to be appended to output */
+{
+ long len = ftell(src);
+ char buf[4096];
+
+ rewind(src);
+ do {
+ size_t maxs =
+ len < (long) sizeof buf ? (size_t) len : sizeof buf;
+ size_t size = fread(buf, 1, maxs, src);
+ fwrite(buf, 1, size, dest);
+ len -= size;
+ if (size < maxs) {
+ break;
+ }
+ } while (len > 0);
+}