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

#include <errno.h>

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

size_t uint640_scan_base_max (char const *s, uint64_t *u, uint8_t base, uint64_t max)
{
  size_t pos = uint64_scan_base_max(s, u, base, max) ;
  if (!pos) return (errno = EINVAL, 0) ;
  if (!s[pos]) return pos ;
  errno = fmtscan_num(s[pos], base) < base ? ERANGE : EINVAL ;
  return 0 ;
}