aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libft.h4
-rw-r--r--src/lst/ft_lstpop_front.c5
-rw-r--r--src/lst/ft_lstreverse.c18
-rw-r--r--src/lst/ft_lstreverse_ret.c26
-rw-r--r--src/str/ft_strict_atoi.c3
-rw-r--r--src/str/ft_strtol.c8
6 files changed, 55 insertions, 9 deletions
diff --git a/include/libft.h b/include/libft.h
index e81f262..a7f86af 100644
--- a/include/libft.h
+++ b/include/libft.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */
-/* Updated: 2020/01/15 11:33:27 by cacharle ### ########.fr */
+/* Updated: 2020/01/15 12:52:37 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -95,6 +95,8 @@ void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *),
void (*del)(void *));
void ft_lstpop_front(t_list **lst, void (*del)(void *));
+t_list *ft_lstreverse_ret(t_list *lst);
+void ft_lstreverse(t_list **lst);
/*
** mem
diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c
index f81315a..f59c9b8 100644
--- a/src/lst/ft_lstpop_front.c
+++ b/src/lst/ft_lstpop_front.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/25 03:32:51 by cacharle #+# #+# */
-/* Updated: 2019/10/25 03:35:58 by cacharle ### ########.fr */
+/* Updated: 2020/01/15 12:46:28 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,6 @@ void ft_lstpop_front(t_list **lst, void (*del)(void *))
if (lst == NULL || *lst == NULL)
return ;
tmp = (*lst)->next;
- del((*lst)->content);
- free(*lst);
+ ft_lstdelone(*lst, del);
*lst = tmp;
}
diff --git a/src/lst/ft_lstreverse.c b/src/lst/ft_lstreverse.c
new file mode 100644
index 0000000..c45a912
--- /dev/null
+++ b/src/lst/ft_lstreverse.c
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstreverse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/15 12:49:14 by cacharle #+# #+# */
+/* Updated: 2020/01/15 12:51:54 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+void ft_lstreverse(t_list **lst)
+{
+ *lst = ft_lstreverse_ret(*lst);
+}
diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c
new file mode 100644
index 0000000..03ae98e
--- /dev/null
+++ b/src/lst/ft_lstreverse_ret.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstreverse_ret.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/15 12:51:15 by cacharle #+# #+# */
+/* Updated: 2020/01/15 13:36:46 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_strict_atoi.c b/src/str/ft_strict_atoi.c
index c25ebdd..6156b03 100644
--- a/src/str/ft_strict_atoi.c
+++ b/src/str/ft_strict_atoi.c
@@ -6,12 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */
-/* Updated: 2020/01/15 11:32:17 by cacharle ### ########.fr */
+/* Updated: 2020/01/15 14:09:03 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 447f1af..0fb5261 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 11:39:34 by cacharle ### ########.fr */
+/* Updated: 2020/01/15 14:15:40 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -65,12 +65,12 @@ long ft_strtol(const char *str, char **endptr, int base)
base = strtol_handle_base(base, &str);
ft_strncpy(base_str, STRTOL_STD_BASE, base);
nb = 0;
- while (ft_strchr(base_str, *str) != NULL)
+ while (ft_strchr(base_str, *str) != base_str + base)
{
nb *= base;
- nb += ft_strchr(base_str, ft_tolower(*str)) - base_str;
+ nb += ft_strchr(base_str, ft_tolower(*str++)) - base_str;
if (((long)nb ^ (long)(nb / base)) < 0)
- return (errno_return(ERANGE));
+ errno = ERANGE;
}
if (endptr != NULL)
*endptr = (char*)str;