skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

uint64_fmt_generic.c (339B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/uint64.h>
      4 #include <skalibs/fmtscan.h>
      5 
      6 size_t uint64_fmt_generic (char *s, uint64_t x, uint8_t base)
      7 {
      8   size_t len = 1 ;
      9   uint64_t q = x ;
     10   while (q >= base) { len++ ; q /= base ; }
     11   if (s)
     12   {
     13     s += len ;
     14     do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ;
     15   }
     16   return len ;
     17 }