#include "philo.h"

static int	ph_isspace(int c)
{
	return (' ' == c || '\f' == c || \
			'\n' == c || '\r' == c || \
			'\t' == c || '\v' == c);
}

static int	ph_isdigit(int c)
{
	return ('0' <= c && '9' >= c);
}

int	ph_atoi(const char *nptr, int *res)
{
	while (ph_isspace(*nptr))
		nptr++;
	*res = 0;
	while (ph_isdigit(*nptr))
		*res = 10 * *res + (*nptr++ - '0');
	if (*nptr != '\0')
		return (FAILURE);
	return (SUCCESS);
}
