Changed Makefile not to use git submodule commands for Libft.
+++ /dev/null
-[submodule "Libft"]
- path = Libft
- url = git://78.102.58.167/Libft.git
+++ /dev/null
-Subproject commit 5cda9c641f76695f327eec126dfb8e9ed91f7792
--- /dev/null
+CC = cc
+CFLAGS = -Wall -Wextra -Werror
+AR = ar
+
+RM = rm -f
+
+INCDIR = .
+SRCDIR = .
+# SOURCES = $(addprefix $(SRCDIR)/, ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c)
+SOURCES = $(shell find $(SRCDIR) -maxdepth 1 -name "*.c")
+OBJECTS = $(SOURCES:.c=.o)
+
+NAME = libft.a
+
+all : $(NAME)
+
+$(NAME) : $(OBJECTS)
+ $(AR) rcs $(NAME) $(OBJECTS)
+
+%.o : %.c
+ $(CC) $(CFLAGS) -o $@ -c $< -I $(INCDIR)
+
+clean :
+ $(RM) $(OBJECTS) $(BONUS_OBJECTS)
+
+fclean : clean
+ $(RM) $(NAME)
+
+re : fclean
+ $(MAKE) all
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_abs.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/09/05 09:48:21 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 11:47:52 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_abs(int n)
+{
+ if (n < 0)
+ return (-n);
+ else
+ return (n);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_atoi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/13 13:44:39 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 17:11:47 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_atoi(const char *nptr)
+{
+ int res;
+ int sign;
+
+ res = 0;
+ sign = 1;
+ while (ft_isspace(*nptr))
+ ++nptr;
+ if ((*nptr == '+' || *nptr == '-'))
+ {
+ if (*nptr == '-')
+ sign *= -1;
+ ++nptr;
+ }
+ while (ft_isdigit(*nptr))
+ {
+ res *= 10;
+ res += *nptr - '0';
+ ++nptr;
+ }
+ return (sign * res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_bzero.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:38:08 by ljiriste #+# #+# */
+/* Updated: 2023/08/14 13:38:32 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+void ft_bzero(void *s, size_t n)
+{
+ ft_memset(s, 0, n);
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_calloc.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 11:34:52 by ljiriste #+# #+# */
+/* Updated: 2023/09/06 13:06:22 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/* This should not be commented as to emulate builtin calloc
+ but errno calls function which is deemed forbidden by Moulinette
+#include <errno.h>
+ if (total_bytes / size != nmemb)
+ {
+ errno = ENOMEM;
+ return (NULL);
+ }
+*/
+#include <stdlib.h> // for malloc
+#include "libft.h"
+
+void *ft_calloc(size_t nmemb, size_t size)
+{
+ size_t total_bytes;
+ void *res;
+
+ if (nmemb == 0 || size == 0)
+ return (malloc(0));
+ total_bytes = nmemb * size;
+ if (total_bytes / size != nmemb)
+ return (NULL);
+ res = malloc(total_bytes);
+ if (res == NULL)
+ return (NULL);
+ ft_memset(res, 0, total_bytes);
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_ctoa.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/09/05 09:55:17 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 09:56:02 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> //malloc
+#include "libft.h"
+
+char *ft_ctoa(char c)
+{
+ char *res;
+
+ res = malloc(2 * sizeof(char));
+ if (res == NULL)
+ return (res);
+ res[0] = c;
+ res[1] = '\0';
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isalnum.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:02:16 by ljiriste #+# #+# */
+/* Updated: 2023/08/14 13:34:41 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isalnum(int c)
+{
+ return (ft_isdigit(c) || ft_isalpha(c));
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isalpha.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:32:19 by ljiriste #+# #+# */
+/* Updated: 2023/08/14 13:32:33 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isalpha(int c)
+{
+ return (ft_isupper(c) || ft_islower(c));
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isascii.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 12:19:40 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 17:10:02 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isascii(int c)
+{
+ return (0x00 <= c && c <= 0x7F);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isdigit.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:32:47 by ljiriste #+# #+# */
+/* Updated: 2023/08/14 13:33:02 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isdigit(int c)
+{
+ return ('0' <= c && c <= '9');
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_islower.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:31:47 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:55:33 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_islower(int c)
+{
+ return ('a' <= c && c <= 'z');
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isprint.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 12:17:32 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:20:22 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isprint(int c)
+{
+ return (0x20 <= c && c <= 0x7E);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isspace.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 11:29:54 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 17:12:30 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isspace(int c)
+{
+ return (c == ' ' || ('\t' <= c && c <= '\r'));
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isupper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:31:05 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:55:24 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_isupper(int c)
+{
+ return ('A' <= c && c <= 'Z');
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_itoa.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 15:58:10 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 17:12:42 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+static unsigned int size_needed(int n)
+{
+ unsigned int res;
+
+ res = 1;
+ if (n == 0)
+ return (2);
+ if (n < 0)
+ ++res;
+ while (n != 0)
+ {
+ ++res;
+ n /= 10;
+ }
+ return (res);
+}
+
+char *ft_itoa(int n)
+{
+ unsigned int size;
+ char *res;
+
+ size = size_needed(n);
+ res = malloc(size * sizeof(char));
+ if (res == NULL)
+ return (res);
+ res[--size] = '\0';
+ if (n == 0 && res)
+ res[0] = '0';
+ else if (n < 0 && res)
+ {
+ res[0] = '-';
+ res[--size] = '0' - (n % 10);
+ n = -(n / 10);
+ }
+ while (n > 0 && res)
+ {
+ res[--size] = '0' + (n % 10);
+ n /= 10;
+ }
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_itoa_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/09/05 09:46:11 by ljiriste #+# #+# */
+/* Updated: 2023/09/08 12:09:56 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> //malloc
+#include <stdint.h> //intmax_t
+#include "libft.h"
+
+static intmax_t abs_max(intmax_t n)
+{
+ if (n < 0)
+ return (-n);
+ else
+ return (n);
+}
+
+static int size_needed(intmax_t n, size_t base_len)
+{
+ int res;
+
+ if (n == 0)
+ return (2);
+ res = 1;
+ if (n < 0)
+ ++res;
+ while (n != 0)
+ {
+ ++res;
+ n /= base_len;
+ }
+ return (res);
+}
+
+static int valid_base(const char *base)
+{
+ int i;
+ int j;
+
+ if (ft_strlen(base) < 2)
+ return (0);
+ i = 0;
+ while (base[i])
+ {
+ j = i + 1;
+ while (base[j])
+ if (base[i] == base[j++])
+ return (0);
+ ++i;
+ }
+ return (1);
+}
+
+char *ft_itoa_base(intmax_t n, const char *base)
+{
+ int size;
+ int base_len;
+ char *res;
+
+ if (!valid_base(base))
+ return (NULL);
+ base_len = ft_strlen(base);
+ size = size_needed(n, base_len);
+ res = malloc(size);
+ if (res == NULL)
+ return (res);
+ if (n < 0)
+ res[0] = '-';
+ res[--size] = '\0';
+ if (n == 0)
+ res[0] = base[0];
+ while (n != 0)
+ {
+ res[--size] = base[abs_max(n % base_len)];
+ n /= base_len;
+ }
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstadd_back.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:33:28 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 16:52:43 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+void ft_lstadd_back(t_list **lst, t_list *new)
+{
+ if (*lst == NULL)
+ {
+ *lst = new;
+ return ;
+ }
+ ft_lstlast(*lst)->next = new;
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstadd_front.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:26:20 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 13:42:49 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+void ft_lstadd_front(t_list **lst, t_list *new)
+{
+ new->next = *lst;
+ *lst = new;
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstclear.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:45:28 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:33:24 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+void ft_lstclear(t_list **lst, void (*del)(void *))
+{
+ t_list *temp;
+
+ if (lst == NULL || del == NULL)
+ return ;
+ while (*lst)
+ {
+ temp = (*lst)->next;
+ ft_lstdelone(*lst, del);
+ *lst = temp;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstdelone.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:43:02 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:33:02 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+void ft_lstdelone(t_list *lst, void (*del)(void *))
+{
+ if (lst == NULL || del == NULL)
+ return ;
+ del(lst->content);
+ free(lst);
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstiter.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:50:31 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 13:51:48 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+void ft_lstiter(t_list *lst, void (*f)(void *))
+{
+ while (lst)
+ {
+ f(lst->content);
+ lst = lst->next;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstlast.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:31:01 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 17:14:03 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+t_list *ft_lstlast(t_list *lst)
+{
+ if (lst == NULL)
+ return (lst);
+ while (lst->next)
+ lst = lst->next;
+ return (lst);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstmap.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:51:57 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 16:58:41 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+static t_list *first_el(t_list *lst, void *(*f)(void *), void (*del)(void *))
+{
+ t_list *res;
+ void *cont;
+
+ if (lst == NULL)
+ return (NULL);
+ cont = f(lst->content);
+ res = ft_lstnew(cont);
+ if (res == NULL)
+ del(cont);
+ return (res);
+}
+
+t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
+{
+ t_list *res;
+ t_list *new_node;
+ void *new_cont;
+
+ res = first_el(lst, f, del);
+ if (res == NULL)
+ return (res);
+ new_node = res;
+ lst = lst->next;
+ while (lst && res)
+ {
+ new_cont = f(lst->content);
+ new_node->next = ft_lstnew(new_cont);
+ new_node = new_node->next;
+ if (new_node == NULL)
+ {
+ del(new_cont);
+ ft_lstclear(&res, del);
+ }
+ lst = lst->next;
+ }
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstnew.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:23:00 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 13:26:10 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+t_list *ft_lstnew(void *content)
+{
+ t_list *res;
+
+ res = malloc(sizeof(t_list));
+ if (res == NULL)
+ return (res);
+ res->content = content;
+ res->next = NULL;
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstsize.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/16 13:28:58 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 14:59:47 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+int ft_lstsize(t_list *lst)
+{
+ int res;
+
+ if (lst == NULL)
+ return (0);
+ res = 1;
+ while (lst->next)
+ {
+ lst = lst->next;
+ ++res;
+ }
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:56:53 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 17:07:39 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include "libft.h"
+
+void *ft_memchr(const void *s, int c, size_t n)
+{
+ size_t i;
+
+ i = 0;
+ while (i < n)
+ {
+ if (*((unsigned char *)s + i) == (unsigned char)c)
+ return ((unsigned char *)s + i);
+ ++i;
+ }
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memcmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 11:06:15 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:53:17 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+int ft_memcmp(const void *s1, const void *s2, size_t n)
+{
+ size_t i;
+
+ i = 0;
+ while (*((unsigned char *)s1 + i) == *((unsigned char *)s2 + i)
+ && i + 1 < n)
+ ++i;
+ if (n > 0)
+ return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i));
+ else
+ return (0);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memcpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:35:59 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:16:35 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include "libft.h"
+
+void *ft_memcpy(void *dest, const void *src, size_t n)
+{
+ if (dest == NULL && src == NULL)
+ return (NULL);
+ while (n > 0)
+ {
+ --n;
+ *((unsigned char *)dest + n) = *((unsigned char *)src + n);
+ }
+ return (dest);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memmove.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:36:32 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 13:17:49 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+void *ft_memmove(void *dest, const void *src, size_t n)
+{
+ size_t i;
+
+ if (dest > src)
+ {
+ i = n;
+ while (i > 0)
+ {
+ --i;
+ *((unsigned char *)dest + i) = *((unsigned char *)src + i);
+ }
+ }
+ else if (dest < src)
+ {
+ i = 0;
+ while (i < n)
+ {
+ *((unsigned char *)dest + i) = *((unsigned char *)src + i);
+ ++i;
+ }
+ }
+ return (dest);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memset.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:13:22 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 10:39:20 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+void *ft_memset(void *s, int c, size_t n)
+{
+ while (n > 0)
+ *((unsigned char *)s + (--n)) = (unsigned char)c;
+ return (s);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_putchar_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 16:20:18 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 16:38:23 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <unistd.h>
+#include "libft.h"
+
+void ft_putchar_fd(char c, int fd)
+{
+ write(fd, &c, 1);
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_putendl_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 16:25:41 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 16:38:32 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <unistd.h>
+#include "libft.h"
+
+void ft_putendl_fd(char *s, int fd)
+{
+ ft_putstr_fd(s, fd);
+ write(fd, "\n", 1);
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_putnbr_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 16:27:25 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 16:38:56 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <unistd.h>
+#include "libft.h"
+
+void ft_putnbr_fd(int n, int fd)
+{
+ char digit;
+
+ if (n < 0)
+ {
+ write(fd, "-", 1);
+ digit = '0' - (n % 10);
+ if (n / 10 != 0)
+ ft_putnbr_fd(-(n / 10), fd);
+ }
+ else if (n < 10)
+ digit = '0' + n;
+ else
+ {
+ digit = '0' + n % 10;
+ ft_putnbr_fd(n / 10, fd);
+ }
+ write(fd, &digit, 1);
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_putstr_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 16:23:36 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:29:20 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <unistd.h>
+#include "libft.h"
+
+void ft_putstr_fd(char *s, int fd)
+{
+ if (s == NULL)
+ return ;
+ write(fd, s, ft_strlen(s));
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_split.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 15:30:26 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 17:53:03 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+static void free_str_array(char **arr)
+{
+ size_t i;
+
+ i = 0;
+ while (arr[i] != NULL)
+ free(arr[i++]);
+ free(arr);
+ return ;
+}
+
+// Returns 0 when terminating null is encountered, otherwise returns true.
+static int to_next_word(const char **s, char c)
+{
+ while (**s && **s == c)
+ ++(*s);
+ return (**s);
+}
+
+static int word_count(const char *s, char c)
+{
+ int count;
+
+ if (s == NULL)
+ return (-1);
+ if (c == '\0')
+ return (1);
+ count = 0;
+ while (*s)
+ {
+ while (*s == c)
+ ++s;
+ if (*s)
+ ++count;
+ while (*s != c && *s)
+ ++s;
+ }
+ return (count);
+}
+
+static size_t strlen_to_char(const char *s, char c)
+{
+ size_t len;
+
+ len = 0;
+ while (s[len] != c && s[len])
+ ++len;
+ return (len);
+}
+
+char **ft_split(const char *s, char c)
+{
+ char **res;
+ size_t size;
+ size_t i;
+
+ res = malloc((word_count(s, c) + 1) * sizeof(char *));
+ if (res == NULL || s == NULL)
+ return (res);
+ i = 0;
+ while (*s)
+ {
+ if (!to_next_word(&s, c))
+ break ;
+ size = (strlen_to_char(s, c) + 1);
+ res[i] = malloc(size * sizeof(char));
+ if (res[i] == NULL)
+ {
+ free_str_array(res);
+ return (NULL);
+ }
+ ft_strlcpy(res[i++], s, size);
+ s += size - 1;
+ }
+ res[i] = NULL;
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:41:10 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 17:10:35 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+char *ft_strchr(const char *s, int c)
+{
+ while (*s)
+ {
+ if (*s == (char)c)
+ return ((char *)s);
+ ++s;
+ }
+ if (c == '\0')
+ return ((char *)s);
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strdup.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/17 13:33:49 by ljiriste #+# #+# */
+/* Updated: 2023/09/11 12:37:12 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> // For the malloc function
+#include "libft.h"
+
+char *ft_strdup(const char *s)
+{
+ char *dest;
+ size_t s_len;
+
+ if (s == NULL)
+ return (NULL);
+ s_len = ft_strlen(s);
+ dest = malloc((s_len + 1) * sizeof(char));
+ if (dest)
+ ft_strlcpy(dest, s, s_len + 1);
+ return (dest);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_striteri.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 16:18:09 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:33:39 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+void ft_striteri(char *s, void (*f)(unsigned int, char *))
+{
+ unsigned int i;
+
+ if (s == NULL || f == NULL)
+ return ;
+ i = 0;
+ while (s[i])
+ {
+ f(i, s + i);
+ ++i;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strjoin.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 15:04:10 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:33:53 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+char *ft_strjoin(const char *s1, const char *s2)
+{
+ char *res;
+ size_t size;
+
+ if (s1 == NULL || s2 == NULL)
+ return (NULL);
+ size = ft_strlen(s1) + ft_strlen(s2) + 1;
+ res = malloc(size * sizeof(char));
+ if (res == NULL)
+ return (res);
+ res[0] = '\0';
+ ft_strlcat(res, s1, size);
+ ft_strlcat(res, s2, size);
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strlcat.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/12 17:32:33 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:40:14 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include <sys/types.h>
+#include "libft.h"
+
+size_t ft_strlcat(char *dst, const char *src, size_t size)
+{
+ size_t length;
+
+ if ((dst == NULL && src == NULL) || size == 0)
+ return (0);
+ length = 0;
+ while (*dst && size > length)
+ {
+ ++dst;
+ ++length;
+ }
+ while (*src && size > length + 1)
+ {
+ *dst = *src;
+ ++src;
+ ++dst;
+ ++length;
+ }
+ if (size > length)
+ *dst = '\0';
+ while (*src)
+ {
+ ++length;
+ ++src;
+ }
+ return (length);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strlcpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/11 17:28:43 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:55:52 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+size_t ft_strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t i;
+
+ i = 0;
+ while (src[i] && i + 1 < size)
+ {
+ dst[i] = src[i];
+ ++i;
+ }
+ if (size > 0)
+ dst[i] = '\0';
+ while (src[i])
+ ++i;
+ return (i);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strlen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/14 13:40:59 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:05:43 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+size_t ft_strlen(const char *s)
+{
+ size_t len;
+
+ len = 0;
+ while (s[len] != '\0')
+ ++len;
+ return (len);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strmapi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 16:12:48 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:32:11 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
+{
+ char *res;
+ unsigned int i;
+
+ if (s == NULL || f == NULL)
+ return (NULL);
+ res = malloc((ft_strlen(s) + 1) * sizeof(char));
+ if (res == NULL)
+ return (NULL);
+ i = 0;
+ while (s[i])
+ {
+ res[i] = f(i, s[i]);
+ ++i;
+ }
+ res[i] = '\0';
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strncmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/12 17:02:07 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:24:25 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "libft.h"
+
+int ft_strncmp(const char *s1, const char *s2, size_t n)
+{
+ size_t i;
+
+ i = 0;
+ while (s1[i] == s2[i] && s1[i] && s2[i] && i + 1 < n)
+ ++i;
+ if (n > 0)
+ return ((unsigned char)s1[i] - (unsigned char)s2[i]);
+ else
+ return (0);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strndup.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/24 09:18:49 by ljiriste #+# #+# */
+/* Updated: 2023/09/27 15:45:36 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> // For the malloc function
+#include "libft.h"
+
+char *ft_strndup(const char *s, size_t n)
+{
+ char *dest;
+ size_t s_len;
+
+ s_len = ft_strlen(s);
+ if (s_len < n)
+ n = s_len;
+ dest = malloc((n + 1) * sizeof(char));
+ if (dest == NULL)
+ return (dest);
+ ft_strlcpy(dest, s, n + 1);
+ return (dest);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strnstr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/12 17:15:34 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:57:24 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h> // For the NULL pointer
+#include <sys/types.h>
+#include "libft.h"
+
+char *ft_strnstr(const char *big, const char *little, size_t len)
+{
+ size_t little_len;
+ size_t i;
+
+ if (little == NULL && len == 0)
+ return ((char *)big);
+ if (*little == '\0')
+ return ((char *)big);
+ if (big == NULL && len == 0)
+ return (NULL);
+ little_len = ft_strlen(little);
+ i = 0;
+ while (big[i] && i + little_len <= len)
+ {
+ if (!(ft_strncmp(big + i, little, little_len)))
+ return ((char *)big + i);
+ ++i;
+ }
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strrchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:46:09 by ljiriste #+# #+# */
+/* Updated: 2023/08/16 13:16:52 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "libft.h"
+
+char *ft_strrchr(const char *s, int c)
+{
+ char *result;
+
+ result = NULL;
+ while (*s)
+ {
+ if (*s == (char)c)
+ result = (char *)s;
+ ++s;
+ }
+ if (c == '\0')
+ return ((char *)s);
+ return (result);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strtrim.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 15:11:52 by ljiriste #+# #+# */
+/* Updated: 2023/09/06 12:58:04 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include "libft.h"
+
+static size_t size_needed(const char *s1, const char *set)
+{
+ size_t at_start;
+ size_t at_end;
+ size_t whole;
+
+ whole = ft_strlen(s1);
+ at_start = 0;
+ at_end = 0;
+ while (ft_strchr(set, *s1) && *s1)
+ {
+ ++s1;
+ ++at_start;
+ }
+ if (*s1 == '\0')
+ return (1);
+ while (*s1)
+ ++s1;
+ --s1;
+ while (ft_strchr(set, *s1))
+ {
+ --s1;
+ ++at_end;
+ }
+ return (whole - at_start - at_end + 1);
+}
+
+char *ft_strtrim(const char *s1, const char *set)
+{
+ size_t size;
+ char *res;
+
+ if (s1 == NULL)
+ return (NULL);
+ size = size_needed(s1, set);
+ res = malloc(size * sizeof(char));
+ if (res == NULL)
+ return (res);
+ while (ft_strchr(set, *s1) && *s1)
+ ++s1;
+ ft_strlcpy(res, s1, size);
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_substr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 15:04:24 by ljiriste #+# #+# */
+/* Updated: 2023/09/05 18:27:38 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "libft.h"
+
+char *ft_substr(const char *s, unsigned int start, size_t len)
+{
+ char *res;
+ size_t size;
+
+ if (s == NULL)
+ return (NULL);
+ size = ft_strlen(s) + 1;
+ if (start > size)
+ {
+ res = malloc(1 * sizeof(char));
+ if (res == NULL)
+ return (NULL);
+ *res = '\0';
+ return (res);
+ }
+ else
+ size -= start;
+ if (size > len + 1)
+ size = len + 1;
+ res = malloc(size * sizeof(char));
+ if (res == NULL)
+ return (NULL);
+ ft_strlcpy(res, s + start, size);
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_tolower.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:36:54 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:53:38 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_tolower(int c)
+{
+ if (ft_isupper(c))
+ c = c + 'a' - 'A';
+ return (c);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_toupper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 10:35:21 by ljiriste #+# #+# */
+/* Updated: 2023/08/15 12:54:28 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_toupper(int c)
+{
+ if (ft_islower(c))
+ c = c + 'A' - 'a';
+ return (c);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_uitoa_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/09/05 09:46:11 by ljiriste #+# #+# */
+/* Updated: 2023/09/15 18:43:25 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h> //malloc
+#include <stdint.h> //intmax_t
+#include "libft.h"
+
+static int size_needed(uintmax_t n, size_t base_len)
+{
+ int res;
+
+ if (n == 0)
+ return (2);
+ res = 1;
+ while (n != 0)
+ {
+ ++res;
+ n /= base_len;
+ }
+ return (res);
+}
+
+static int valid_base(const char *base)
+{
+ int i;
+ int j;
+
+ if (ft_strlen(base) < 2)
+ return (0);
+ i = 0;
+ while (base[i])
+ {
+ j = i + 1;
+ while (base[j])
+ if (base[i] == base[j++])
+ return (0);
+ ++i;
+ }
+ return (1);
+}
+
+char *ft_uitoa_base(uintmax_t n, const char *base)
+{
+ int size;
+ int base_len;
+ char *res;
+
+ if (!valid_base(base))
+ return (NULL);
+ base_len = ft_strlen(base);
+ size = size_needed(n, base_len);
+ res = malloc(size);
+ if (res == NULL)
+ return (res);
+ res[--size] = '\0';
+ if (n == 0)
+ res[0] = base[0];
+ while (n != 0)
+ {
+ res[--size] = base[n % base_len];
+ n /= base_len;
+ }
+ return (res);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/08/15 12:58:15 by ljiriste #+# #+# */
+/* Updated: 2023/09/15 18:43:23 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_H
+# define LIBFT_H
+
+# include <sys/types.h>
+# include <stdint.h>
+
+int ft_isalnum(int c);
+int ft_isalpha(int c);
+int ft_isdigit(int c);
+int ft_islower(int c);
+int ft_isprint(int c);
+int ft_isspace(int c);
+int ft_isupper(int c);
+int ft_isascii(int c);
+
+int ft_abs(int n);
+
+void *ft_memset(void *s, int c, size_t n);
+void *ft_memcpy(void *dest, const void *src, size_t n);
+void *ft_memmove(void *dest, const void *src, size_t n);
+void *ft_memchr(const void *s, int c, size_t n);
+void *ft_calloc(size_t nmemb, size_t size);
+void ft_bzero(void *s, size_t n);
+int ft_memcmp(const void *s1, const void *s2, size_t n);
+
+size_t ft_strlen(const char *s);
+size_t ft_strlcpy(char *dst, const char *src, size_t size);
+size_t ft_strlcat(char *dst, const char *src, size_t size);
+int ft_strncmp(const char *s1, const char *s2, size_t n);
+char *ft_strchr(const char *s, int c);
+char *ft_strrchr(const char *s, int c);
+char *ft_strnstr(const char *big, const char *little, size_t len);
+char *ft_strdup(const char *s);
+char *ft_strndup(const char *s, size_t n);
+
+int ft_toupper(int c);
+int ft_tolower(int c);
+
+int ft_atoi(const char *nptr);
+
+char *ft_substr(const char *s, unsigned int start, size_t len);
+char *ft_strjoin(const char *s1, const char *s2);
+char *ft_strtrim(const char *s1, const char *set);
+char **ft_split(const char *s, char c);
+
+char *ft_itoa(int n);
+char *ft_itoa_base(intmax_t n, const char *base);
+char *ft_uitoa_base(uintmax_t n, const char *base);
+char *ft_ctoa(char c);
+
+char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
+void ft_striteri(char *s, void (*f)(unsigned int, char *));
+
+void ft_putchar_fd(char c, int fd);
+void ft_putstr_fd(char *s, int fd);
+void ft_putendl_fd(char *s, int fd);
+void ft_putnbr_fd(int n, int fd);
+
+typedef struct s_list
+{
+ void *content;
+ struct s_list *next;
+} t_list;
+
+t_list *ft_lstnew(void *content);
+void ft_lstadd_front(t_list **lst, t_list *new);
+int ft_lstsize(t_list *lst);
+t_list *ft_lstlast(t_list *lst);
+void ft_lstadd_back(t_list **lst, t_list *new);
+void ft_lstdelone(t_list *lst, void (*del)(void *));
+void ft_lstclear(t_list **lst, void (*del)(void *));
+void ft_lstiter(t_list *lst, void (*f)(void *));
+t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
+
+#endif
cp Libft/libft.a $(NAME)
$(AR) rcs $(NAME) $(OBJECTS)
-Libft/libft.a : Libft/libft.h
+Libft/libft.a :
$(MAKE) -C ./Libft
-%.o : %.c Libft/libft.h
+%.o : %.c
$(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE)
clean :
re : fclean
$(MAKE) all
-Libft/libft.h :
- git submodule update --init Libft
- git -C ./Libft checkout no_crash
-
bonus : all
-
-.PHONY : Libft