diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/io/ft_getchar.c | 22 | ||||
| -rw-r--r-- | src/lst/ft_lstreverse_ret.c | 27 | ||||
| -rw-r--r-- | src/str/ft_atoi_strict.c | 38 |
3 files changed, 87 insertions, 0 deletions
diff --git a/src/io/ft_getchar.c b/src/io/ft_getchar.c new file mode 100644 index 0000000..54b44d4 --- /dev/null +++ b/src/io/ft_getchar.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_getchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/18 10:29:54 by cacharle #+# #+# */ +/* Updated: 2020/01/18 10:46:56 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char ft_getchar(void) +{ + char c; + + if (read(STDIN_FILENO, &c, 1) < 0) + return (-1); + return (c); +} diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c new file mode 100644 index 0000000..caf6ec1 --- /dev/null +++ b/src/lst/ft_lstreverse_ret.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstreverse_ret.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/15 12:51:15 by cacharle #+# #+# */ +/* Updated: 2020/01/18 11:52:50 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstreverse_ret(t_list *lst) +{ + t_list *tmp; + + if (lst == NULL) + return (NULL); + if (lst->next == NULL) + return (lst); + tmp = ft_lstreverse_ret(lst->next); + lst->next->next = lst; + lst->next = NULL; + return (tmp); +} diff --git a/src/str/ft_atoi_strict.c b/src/str/ft_atoi_strict.c new file mode 100644 index 0000000..f12e8db --- /dev/null +++ b/src/str/ft_atoi_strict.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strict_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */ +/* Updated: 2020/01/18 11:53:07 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strict_atoi(const char *s) +{ + char *end; + long ret; + + if (*s != '-' && !ft_isdigit(*s)) + { + errno = EINVAL; + return (0); + } + errno = 0; + ret = ft_strtol(s, &end, 10); + if (errno == ERANGE || ret > INT_MAX || ret < INT_MIN) + { + errno = ERANGE; + return (0); + } + if (*end != '\0') + { + errno = EINVAL; + return (0); + } + return (ret); +} |
