diff options
author | cmiller@zippy.cornsilk.net <> | 2007-04-23 17:58:33 -0400 |
---|---|---|
committer | cmiller@zippy.cornsilk.net <> | 2007-04-23 17:58:33 -0400 |
commit | d81f116534da25fda68e61d7641cf3a05186daf2 (patch) | |
tree | e00fbe7afe272a3fc90f10889b77fda3834daaff /mysys/mf_iocache2.c | |
parent | dfdc475a579e7448b68c36c4cb3d43a16fd121cb (diff) | |
download | mariadb-git-d81f116534da25fda68e61d7641cf3a05186daf2.tar.gz |
Contributed patch from Jorge Bernal Ordovás. CLA#42
Bug#27894: mysqlbinlog formats timestamp wrong in comment
Date stamps lack zero padding, and so are meaningless.
Implement minimum-width zero padding for the percent-escape sequences
used in the logging code.
Diffstat (limited to 'mysys/mf_iocache2.c')
-rw-r--r-- | mysys/mf_iocache2.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c index bdb5d057a16..1d33b88e269 100644 --- a/mysys/mf_iocache2.c +++ b/mysys/mf_iocache2.c @@ -299,6 +299,7 @@ uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args) uint minimum_width; /* as yet unimplemented */ uint minimum_width_sign; uint precision; /* as yet unimplemented for anything but %b */ + my_bool is_zero_padded; /* Store the location of the beginning of a format directive, for the @@ -334,11 +335,27 @@ uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args) backtrack= fmt; fmt++; + is_zero_padded= FALSE; + minimum_width_sign= 1; minimum_width= 0; precision= 0; - minimum_width_sign= 1; /* Skip if max size is used (to be compatible with printf) */ - while (*fmt == '-') { fmt++; minimum_width_sign= -1; } + +process_flags: + switch (*fmt) + { + case '-': + minimum_width_sign= -1; fmt++; goto process_flags; + case '0': + is_zero_padded= TRUE; fmt++; goto process_flags; + case '#': + /** @todo Implement "#" conversion flag. */ fmt++; goto process_flags; + case ' ': + /** @todo Implement " " conversion flag. */ fmt++; goto process_flags; + case '+': + /** @todo Implement "+" conversion flag. */ fmt++; goto process_flags; + } + if (*fmt == '*') { precision= (int) va_arg(args, int); fmt++; @@ -367,7 +384,7 @@ uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args) { reg2 char *par = va_arg(args, char *); uint length2 = (uint) strlen(par); - /* TODO: implement minimum width and precision */ + /* TODO: implement precision */ out_length+= length2; if (my_b_write(info, par, length2)) goto err; @@ -390,6 +407,21 @@ uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args) length2= (uint) (int10_to_str((long) iarg,buff, -10) - buff); else length2= (uint) (int10_to_str((long) (uint) iarg,buff,10)- buff); + + /* minimum width padding */ + if (minimum_width > length2) + { + char *buffz; + + buffz= my_alloca(minimum_width - length2); + if (is_zero_padded) + memset(buffz, '0', minimum_width - length2); + else + memset(buffz, ' ', minimum_width - length2); + my_b_write(info, buffz, minimum_width - length2); + my_afree(buffz); + } + out_length+= length2; if (my_b_write(info, buff, length2)) goto err; |