aboutsummaryrefslogtreecommitdiff
path: root/src/str
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-18 11:54:47 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-18 11:54:47 +0100
commit676b37f963789f3d85b18ed5b3708374971b65e2 (patch)
treeac95f340a31768139129f3e76e598692963ea274 /src/str
parentae1412fdc283e442a0869aa7d63778449a7e5cfe (diff)
downloadlibft-676b37f963789f3d85b18ed5b3708374971b65e2.tar.gz
libft-676b37f963789f3d85b18ed5b3708374971b65e2.tar.bz2
libft-676b37f963789f3d85b18ed5b3708374971b65e2.zip
Added ft_getchar and fixing strtol
Diffstat (limited to 'src/str')
-rw-r--r--src/str/ft_atoi_strict.c3
-rw-r--r--src/str/ft_strtol.c12
2 files changed, 8 insertions, 7 deletions
diff --git a/src/str/ft_atoi_strict.c b/src/str/ft_atoi_strict.c
index 6156b03..f12e8db 100644
--- a/src/str/ft_atoi_strict.c
+++ b/src/str/ft_atoi_strict.c
@@ -6,13 +6,12 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */
-/* Updated: 2020/01/15 14:09:03 by cacharle ### ########.fr */
+/* Updated: 2020/01/18 11:53:07 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
-#include <stdio.h>
int ft_strict_atoi(const char *s)
{
char *end;
diff --git a/src/str/ft_strtol.c b/src/str/ft_strtol.c
index 0fb5261..7fab7ed 100644
--- a/src/str/ft_strtol.c
+++ b/src/str/ft_strtol.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/15 10:26:45 by cacharle #+# #+# */
-/* Updated: 2020/01/15 14:15:40 by cacharle ### ########.fr */
+/* Updated: 2020/01/18 11:52:22 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,6 +16,8 @@
static int 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')
@@ -55,17 +57,17 @@ long ft_strtol(const char *str, char **endptr, int base)
long long nb;
char base_str[37];
- if (base > 36)
- return (errno_return(EINVAL));
while (ft_isspace(*str))
str++;
is_negative = *str == '-' ? TRUE : FALSE;
if (*str == '-' || *str == '+')
str++;
- base = strtol_handle_base(base, &str);
+ if ((base = strtol_handle_base(base, &str)) == -1)
+ return (errno_return(EINVAL));
ft_strncpy(base_str, STRTOL_STD_BASE, base);
+ base_str[base] = '\0';
nb = 0;
- while (ft_strchr(base_str, *str) != base_str + base)
+ while (*str != '\0' && ft_strchr(base_str, *str) != NULL)
{
nb *= base;
nb += ft_strchr(base_str, ft_tolower(*str++)) - base_str;