38 lines
1.3 KiB
C
38 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: o_ :::::: ::: */
|
|
/* ph_atoi.c :+: / :+::+: :+: */
|
|
/* +:+ > +:++:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
|
/* Created: 2025/01/20 14:27:09 by whaffman #+#+# #+#+# #+# #+# | */
|
|
/* Updated: 2025/01/27 14:14:05 by whaffman ### ### ### ### / \ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#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);
|
|
}
|