about summary refs log tree commit diff
path: root/src/stdlib/strtoul.c
blob: 20d8bfb28f0ab2f45506d0ae7d09cd0773e9d7fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include <limits.h>

unsigned long strtoul(const char *s, char **p, int base)
{
	intmax_t x;
	if (sizeof(intmax_t) == sizeof(long))
		return strtoumax(s, p, base);
	x = strtoimax(s, p, base);
	if (-x > ULONG_MAX || x > ULONG_MAX) {
		errno = ERANGE;
		return ULONG_MAX;
	}
	return x;
}