summaryrefslogtreecommitdiff
path: root/src/libstddjb/uint64_fmt.c
blob: cbe3382d60ad07417467a6ffc37ed78886238121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* ISC license. */

#include <skalibs/uint64.h>
#include <skalibs/fmtscan.h>

unsigned int uint64_fmt_base (char *s, uint64 x, unsigned char base)
{
  register unsigned int len = 1 ;
  {
    register uint64 q = x ;
    while (q >= base) { len++ ; q /= base ; }
  }
  if (s)
  {
    s += len ;
    do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ;
  }
  return len ;
}