1 /* ISC license. */
2 
3 #include <skalibs/uint64.h>
4 #include <skalibs/fmtscan.h>
5 
uint64_scan_base_max(char const * s,uint64_t * u,uint8_t base,uint64_t max)6 size_t uint64_scan_base_max (char const *s, uint64_t *u, uint8_t base, uint64_t max)
7 {
8   uint64_t result = 0 ;
9   size_t pos = 0 ;
10   for (;; pos++)
11   {
12     uint8_t c = fmtscan_num(s[pos], base) ;
13     if (c >= base || result > ((max - c) / base)) break ;
14     result = result * base + c ;
15   }
16   if (pos) *u = result ;
17   return pos ;
18 }
19