aboutsummaryrefslogtreecommitdiff
path: root/test_mini/libft/src/str/ft_strtol.c
diff options
context:
space:
mode:
authornass1pro <nass1pro@gmail.com>2020-06-12 13:52:58 +0200
committernass1pro <nass1pro@gmail.com>2020-06-13 11:45:50 +0200
commitd971bd8d16608f316396aba7a579d0b1f1af5aeb (patch)
tree98ec558582ed20a120e13b4a376fd206fb620da0 /test_mini/libft/src/str/ft_strtol.c
parent3136f59540a8dd29e2f096be5a8943e2ddd28431 (diff)
downloadminishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.tar.gz
minishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.tar.bz2
minishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.zip
Added e_token enum
Diffstat (limited to 'test_mini/libft/src/str/ft_strtol.c')
-rw-r--r--test_mini/libft/src/str/ft_strtol.c80
1 files changed, 0 insertions, 80 deletions
diff --git a/test_mini/libft/src/str/ft_strtol.c b/test_mini/libft/src/str/ft_strtol.c
deleted file mode 100644
index 82276d8..0000000
--- a/test_mini/libft/src/str/ft_strtol.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_strtol.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/15 10:26:45 by cacharle #+# #+# */
-/* Updated: 2020/02/10 02:21:16 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-
-#define STRTOL_STD_BASE "0123456789abcdefghijklmnopqrstuvwxyz"
-
-static int st_strtol_handle_base(int base, const char **str)
-{
- if (base > 36)
- return (-1);
- if (base != 16 && base != 0)
- return (base);
- if (base == 16 && **str == '0' && (*str)[1] == 'x')
- {
- *str += 2;
- return (base);
- }
- if (**str == '0')
- {
- (*str)++;
- if (**str == 'x')
- {
- (*str)++;
- return (16);
- }
- else
- return (8);
- }
- return (10);
-}
-
-static long st_errno_return(int err)
-{
- errno = err;
- return (0);
-}
-
-/*
-** If there is no digits doesn't put str in endptr like the original,
-** instead it puts the address of the char after spaces and sign.
-** Too much lines and annoyance, I can't be bothered.
-*/
-
-long ft_strtol(const char *str, char **endptr, int base)
-{
- t_ftbool is_negative;
- long long nb;
- char base_str[37];
-
- while (ft_isspace(*str))
- str++;
- is_negative = *str == '-' ? TRUE : FALSE;
- if (*str == '-' || *str == '+')
- str++;
- if ((base = st_strtol_handle_base(base, &str)) == -1)
- return (st_errno_return(EINVAL));
- ft_strncpy(base_str, STRTOL_STD_BASE, base);
- base_str[base] = '\0';
- nb = 0;
- while (*str != '\0' && ft_strchr(base_str, *str) != NULL)
- {
- nb *= base;
- nb += ft_strchr(base_str, ft_tolower(*str++)) - base_str;
- if (((long)nb ^ (long)(nb / base)) < 0)
- errno = ERANGE;
- }
- if (endptr != NULL)
- *endptr = (char*)str;
- return (is_negative ? -nb : nb);
-}