From 91f79ea6637ba22ae1c11c758cdf30095db8a52b Mon Sep 17 00:00:00 2001 From: ariard Date: Tue, 4 Jul 2017 17:40:24 +0200 Subject: [PATCH] with lst_pop propre --- libft/Makefile | 2 ++ libft/includes/lst.h | 2 ++ libft/includes/str.h | 2 ++ libft/srcs/lst/ft_lst_pop.c | 11 +++++++++++ libft/srcs/str/ft_strndup.c | 12 ++++++++++++ 5 files changed, 29 insertions(+) create mode 100644 libft/srcs/lst/ft_lst_pop.c create mode 100644 libft/srcs/str/ft_strndup.c diff --git a/libft/Makefile b/libft/Makefile index eb4ddbe0..060feedc 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -104,6 +104,7 @@ lst/ft_lstnew.c\ lst/ft_lstnew_range.c\ lst/ft_lstsort.c\ lst/lst_insert_sort.c\ +lst/ft_lst_pop.c\ lst/pop.c\ lst/push.c\ lst/top.c\ @@ -168,6 +169,7 @@ str/ft_strcspn.c\ str/ft_strcut.c\ str/ft_strdel.c\ str/ft_strdup.c\ +str/ft_strndup.c\ str/ft_strdupchr.c\ str/ft_strduptr.c\ str/ft_strequ.c\ diff --git a/libft/includes/lst.h b/libft/includes/lst.h index 3f4adb6a..390903ad 100644 --- a/libft/includes/lst.h +++ b/libft/includes/lst.h @@ -88,4 +88,6 @@ t_list *ft_lst_at(t_list *list, unsigned int nbr); void lst_insert_sort(t_list **head, int (cmp)()); +t_list *ft_lst_pop(t_list **lst); + #endif diff --git a/libft/includes/str.h b/libft/includes/str.h index 44325726..3db450ed 100644 --- a/libft/includes/str.h +++ b/libft/includes/str.h @@ -72,4 +72,6 @@ size_t ft_strcspn(char *s, const char *delim); char *ft_path_notdir(char *path); int ft_stris(char *str, int (*f)()); +char *ft_strndup(const char *s1, size_t n); + #endif diff --git a/libft/srcs/lst/ft_lst_pop.c b/libft/srcs/lst/ft_lst_pop.c new file mode 100644 index 00000000..47d8f606 --- /dev/null +++ b/libft/srcs/lst/ft_lst_pop.c @@ -0,0 +1,11 @@ +#include "libft.h" + +t_list *ft_lst_pop(t_list **lst) +{ + t_list *top; + + top = *lst; + if (lst && *lst) + *lst = (*lst)->next; + return (top); +} diff --git a/libft/srcs/str/ft_strndup.c b/libft/srcs/str/ft_strndup.c new file mode 100644 index 00000000..ff3ed5be --- /dev/null +++ b/libft/srcs/str/ft_strndup.c @@ -0,0 +1,12 @@ + +#include "libft.h" + +char *ft_strndup(const char *s1, size_t n) +{ + char *dup; + + if (!(dup = ft_memalloc(n))) + return (NULL); + ft_strncpy(dup, s1, n); + return (dup); +}