summaryrefslogblamecommitdiff
path: root/src/stdlib/strtoul.c
blob: 20d8bfb28f0ab2f45506d0ae7d09cd0773e9d7fe (plain) (tree)
1
2
3
4
5
6
7






                                                        




                                              




                                 
#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;
}