/*   ltoa.c  -- not quite standard long-to-string, any base <= 16    */
#ifndef EXEC_TYPES_H
#include "exec/types.h"
#endif
SHORT ltoa(str, val, base)    /*  convert long int 'val' to string 'str'  */
UBYTE *str;                   /*  returns SHORT = strlen(str)             */
LONG val;
SHORT base;
{
static char numchar[17] = "0123456789ABCDEF";
static char tstr[20] = "";
LONG div, lbase, rem;
SHORT ilt, jlt, len;
if (base < 2 || base > 16) lbase = 10L;
else lbase = (long)base;
div = 0;
div = (val >=0L)? val : -val;
ilt = 0;
if(div == 0L) {tstr[0] = numchar[0]; ilt ++;}
while (div > 0L)
     {
     rem = div%lbase;
     tstr[ilt] = numchar[rem];
     div = div/lbase;
     ilt ++;
     }
if (val < 0L) { tstr[ilt] = '-'; ilt ++; }
tstr[ilt] = '\0';
len = ilt;
jlt = len -1;
for (ilt = 0; ilt < len; ilt ++)
     {
     str[ilt] = tstr[jlt];
     jlt --;
     }
str[len] = '\0';
return len;
}
