summaryrefslogtreecommitdiff
path: root/strings/my_vsnprintf.c
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2004-04-08 17:56:45 +0300
committerunknown <monty@mysql.com>2004-04-08 17:56:45 +0300
commit10e15762b8e38ae09d89e6489de6f2fe68cfd85e (patch)
tree1eb8cd825c2490f5f90d6e08cd2b0338ce489853 /strings/my_vsnprintf.c
parent46bd7be2409e80b36de3cd0d49af33557ffa74a9 (diff)
downloadmariadb-git-10e15762b8e38ae09d89e6489de6f2fe68cfd85e.tar.gz
Don't enable HA_EXTRA_WRITE_CACHE if too few rows
Revert main parts of patch for online index builds. Should be done differently Added support for %lx in my_snprintf() sql/ha_myisam.cc: Don't enable HA_EXTRA_WRITE_CACHE if too few rows sql/handler.h: Indentaion fix sql/mysql_priv.h: Removed real_alter_table, mysql_add_column and mysql_drop_column sql/sql_class.cc: After merge fix sql/sql_insert.cc: Don't user bulk_insert if only one row (common case) sql/sql_parse.cc: Added mysql_create_index() and mysql_drop_index() as these are only wrappers for mysql_alter_table() sql/sql_table.cc: Revert main parts of patch for online index builds Changed back to use tabs to make merges possible between trees sql/unireg.cc: Added comments and minor cleanup strings/my_vsnprintf.c: Added support for %lx. Proper long support
Diffstat (limited to 'strings/my_vsnprintf.c')
-rw-r--r--strings/my_vsnprintf.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
index 4fd288d257e..d9d80263d31 100644
--- a/strings/my_vsnprintf.c
+++ b/strings/my_vsnprintf.c
@@ -25,8 +25,9 @@
IMPLEMENTION:
Supports following formats:
- %#d
- %#u
+ %#[l]d
+ %#[l]u
+ %#[l]x
%#.#s Note #.# is skiped
RETURN
@@ -47,7 +48,7 @@ int my_snprintf(char* to, size_t n, const char* fmt, ...)
int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
{
char *start=to, *end=to+n-1;
- uint length, num_state, pre_zero;
+ uint length, num_state, pre_zero, have_long;
for (; *fmt ; fmt++)
{
@@ -62,7 +63,7 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
/* Read max fill size (only used with %d and %u) */
if (*fmt == '-')
fmt++;
- length= num_state= pre_zero= 0;
+ length= num_state= pre_zero= have_long= 0;
for (;; fmt++)
{
if (my_isdigit(&my_charset_latin1,*fmt))
@@ -80,7 +81,10 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
num_state= 1;
}
if (*fmt == 'l')
+ {
fmt++;
+ have_long= 1;
+ }
if (*fmt == 's') /* String parameter */
{
reg2 char *par = va_arg(ap, char *);
@@ -92,20 +96,29 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
to=strnmov(to,par,plen);
continue;
}
- else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */
+ else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x') /* Integer parameter */
{
- register int iarg;
+ register long larg;
uint res_length, to_length;
char *store_start= to, *store_end;
- char buff[16];
+ char buff[32];
if ((to_length= (uint) (end-to)) < 16 || length)
store_start= buff;
- iarg = va_arg(ap, int);
+ if (have_long)
+ larg = va_arg(ap, long);
+ else
+ if (*fmt == 'd')
+ larg = va_arg(ap, int);
+ else
+ larg= (long) (uint) va_arg(ap, int);
if (*fmt == 'd')
- store_end= int10_to_str((long) iarg, store_start, -10);
+ store_end= int10_to_str(larg, store_start, -10);
else
- store_end= int10_to_str((long) (uint) iarg, store_start, 10);
+ if (*fmt== 'u')
+ store_end= int10_to_str(larg, store_start, 10);
+ else
+ store_end= int2str(larg, store_start, 16);
if ((res_length= (uint) (store_end - store_start)) > to_length)
break; /* num doesn't fit in output */
/* If %#d syntax was used, we have to pre-zero/pre-space the string */
@@ -146,7 +159,7 @@ static void my_printf(const char * fmt, ...)
n = my_vsnprintf(buf, sizeof(buf)-1,fmt, ar);
printf(buf);
printf("n=%d, strlen=%d\n", n, strlen(buf));
- if (buf[sizeof(buf)-1] != OVERRUN_SENTRY)
+ if ((uchar) buf[sizeof(buf)-1] != OVERRUN_SENTRY)
{
fprintf(stderr, "Buffer overrun\n");
abort();
@@ -167,6 +180,7 @@ int main()
my_printf("Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "hack");
my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1);
my_printf("Hello %u\n", 1);
+ my_printf("Hex: %lx '%6lx'\n", 32, 65);
my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\
`%-.64s' (%-.64s)", 1, 0,0,0,0);
return 0;