Rename single-argument ltoa and ultoa to _ltoa and _ultoa.
Rename non-standard ltostr and ultostr to __ltostr and __ultostr, change
prototypes in stdlib.h to match expected arguments.
New implementations of ltoa, ultoa based on __ltostr, __ultostr.
Change vfprintf to call __ltostr and __ultostr.
Change _itoa to call _ltoa.
Now we have:
_ltoa, _ultoa, _itoa: Take a single argument (value).
__ltostr, __ultostr: Take two arguments (value, radix).
ltoa, ultoa: Take three arguments (value, buffer, radix). Calls either
__ltostr or __ultostr and copies the result into the user-provided
buffer.
extern char *_ltoa __P((long value));
extern char *_ultoa __P((unsigned long value));
-extern char *ultostr __P((unsigned long value, char *buf, int radix));
-extern char *ltostr __P((long value, char *buf, int radix));
+extern char *__ultostr __P((unsigned long value, int radix));
+extern char *__ltostr __P((long value, int radix));
extern long strtol __P ((const char * nptr, char ** endptr, int base));
extern unsigned long strtoul __P ((const char * nptr,
*/
-char * ultoa(unsigned long val)
+char *_ultoa(unsigned long val)
{
char *p;
static char buf[12];
return p;
}
-char * ltoa(long val)
+char *_ltoa(long val)
{
char *p;
int flg = 0;
if( val < 0 ) { flg++; val= -val; }
- p = ultoa(val);
+ p = _ultoa(val);
if(flg) *--p = '-';
return p;
}
* under the GNU Library General Public License.
*/
+#include <string.h>
+
static char buf[34];
-char * ultostr(unsigned long val, int radix)
+char * __ultostr(unsigned long val, int radix)
{
register char *p;
register int c;
return p;
}
-char * ltostr(long val, int radix)
+char * __ltostr(long val, int radix)
{
char *p;
int flg = 0;
if( val < 0 ) { flg++; val= -val; }
- p = ultostr(val, radix);
+ p = __ultostr(val, radix);
if(p && flg) *--p = '-';
return p;
}
+
+/* sadly we do not know the size of the user-provided buffer so we cannot write
+ it backwards, so just copy the result from our own buffer whose size we know */
+
+char *ultoa (unsigned long value, char *strP, int radix)
+{
+ return strcpy(strP, __ultostr(value, radix));
+}
+
+char *ltoa (long value, char *strP, int radix)
+{
+ return strcpy(strP, __ltostr(value, radix));
+}
case 'd': /* Signed decimal */
case 'i':
- ptmp = ltostr((long) ((lval) ?
+ ptmp = __ltostr((long) ((lval) ?
va_arg(ap, long) :
- va_arg(ap, short)),
- tmp, 10);
+ va_arg(ap, short)), 10);
goto printit;
case 'b': /* Unsigned binary */
usproc:val = lval ? va_arg(ap, unsigned long) :
va_arg(ap,
unsigned short);
- ptmp = ultostr(val, tmp + 4, radix);
+ ptmp = __ultostr(val, radix);
add = "";
if (hash) {
if (radix == 2)
/*********************** xitoa.c ***************************/
char *_itoa(int i)
{
- static char buf[16];
- return ltostr((long) i, buf, 10);
+ return _ltoa((long)i);
}