2022-12-29 02:54:59 -05:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-02-01 03:58:51 -05:00
|
|
|
/** `printf`-compatible substring. */
|
|
|
|
struct substring { const char *sub; int size; };
|
|
|
|
|
2022-12-29 02:54:59 -05:00
|
|
|
/** Parse unsigned; [`s`,`e`) => `n`. */
|
|
|
|
static int helper_natural(const char *s, const char *const e, uint32_t *const n)
|
|
|
|
{
|
|
|
|
uint32_t accum = 0;
|
|
|
|
while(s < e) {
|
|
|
|
unsigned next = accum * 10 + (unsigned)(*s - '0');
|
|
|
|
if(accum >= next) return errno = ERANGE, 0;
|
|
|
|
accum = next;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
*n = accum;
|
|
|
|
return 1;
|
|
|
|
}
|