summaryrefslogtreecommitdiff
path: root/src/stdlib/strtol.c
blob: ace820afef89a3895343e332fb7d2db4e4068bdd (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>

long strtol(const char *s, char **p, int base)
{
	intmax_t x = strtoimax(s, p, base);
	if (x > LONG_MAX) {
		errno = ERANGE;
		return LONG_MAX;
	} else if (x < LONG_MIN) {
		errno = ERANGE;
		return LONG_MIN;
	}
	return x;
}