diff options
author | MySQL Team <mysql@php.net> | 2000-08-22 09:02:46 +0000 |
---|---|---|
committer | MySQL Team <mysql@php.net> | 2000-08-22 09:02:46 +0000 |
commit | 4b1380e31c0f6e76c629611c7ba8c4e2e961a2fd (patch) | |
tree | 853d1881366287956bbfa7edf2f4edc0ae62637e /ext/mysql/libmysql/int2str.c | |
parent | bac08af4cb97ea7e9db18a4267fb070264792f2f (diff) | |
download | php-git-4b1380e31c0f6e76c629611c7ba8c4e2e961a2fd.tar.gz |
New files for MySQL 3.23.23 client library. New files are for qouting
using different character sets.
Diffstat (limited to 'ext/mysql/libmysql/int2str.c')
-rw-r--r-- | ext/mysql/libmysql/int2str.c | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/ext/mysql/libmysql/int2str.c b/ext/mysql/libmysql/int2str.c index 9d6d435721..4003e8a616 100644 --- a/ext/mysql/libmysql/int2str.c +++ b/ext/mysql/libmysql/int2str.c @@ -1,3 +1,20 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + /* Defines: int2str(), itoa(), ltoa() @@ -33,6 +50,7 @@ char *int2str(register long int val, register char *dst, register int radix) { char buffer[65]; register char *p; + long int new_val; if (radix < 0) { if (radix < -36 || radix > -2) return NullS; @@ -57,8 +75,9 @@ char *int2str(register long int val, register char *dst, register int radix) */ p = &buffer[sizeof(buffer)-1]; *p = '\0'; - *--p = _dig_vec[(ulong) val % (ulong) radix]; - val = (ulong) val / (ulong) radix; + new_val=(ulong) val / (ulong) radix; + *--p = _dig_vec[(uchar) ((ulong) val- (ulong) new_val*(ulong) radix)]; + val = new_val; #ifdef HAVE_LDIV while (val != 0) { @@ -70,14 +89,53 @@ char *int2str(register long int val, register char *dst, register int radix) #else while (val != 0) { - *--p = _dig_vec[val%radix]; - val /= radix; + new_val=val/radix; + *--p = _dig_vec[(uchar) (val-new_val*radix)]; + val= new_val; } #endif while ((*dst++ = *p++) != 0) ; return dst-1; } + +/* + This is a faster version of the above optimized for the normal case of + radix 10 / -10 +*/ + +char *int10_to_str(long int val,char *dst,int radix) +{ + char buffer[65]; + register char *p; + long int new_val; + + if (radix < 0) /* -10 */ + { + if (val < 0) + { + *dst++ = '-'; + val = -val; + } + } + + p = &buffer[sizeof(buffer)-1]; + *p = '\0'; + new_val= (long) ((unsigned long int) val / 10); + *--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10); + val = new_val; + + while (val != 0) + { + new_val=val/10; + *--p = '0' + (char) (val-new_val*10); + val= new_val; + } + while ((*dst++ = *p++) != 0) ; + return dst-1; +} + + #ifdef USE_MY_ITOA /* Change to less general itoa interface */ |