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

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

size_t uint64_fmt_generic (char *s, uint64_t x, uint8_t base)
{
  size_t len = 1 ;
  uint64_t q = x ;
  while (q >= base) { len++ ; q /= base ; }
  if (s)
  {
    s += len ;
    do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ;
  }
  return len ;
}