├── .vscode └── settings.json ├── README.md ├── src ├── is │ ├── ft_isascii.c │ ├── ft_isdigit.c │ ├── ft_isprint.c │ ├── ft_isalnum.c │ └── ft_isalpha.c ├── put │ ├── ft_putchar_fd.c │ ├── ft_putstr_fd.c │ ├── ft_putendl_fd.c │ ├── ft_putunbr_fd.c │ ├── ft_puthexa_fd.c │ └── ft_putnbr_fd.c ├── mem │ ├── ft_bzero.c │ ├── ft_calloc.c │ ├── ft_memset.c │ ├── ft_memchr.c │ ├── ft_memcpy.c │ ├── ft_memcmp.c │ └── ft_memmove.c ├── lst │ ├── ft_lstadd_front.c │ ├── ft_lstdelone.c │ ├── ft_lstiter.c │ ├── ft_lstadd_back.c │ ├── ft_lstlast.c │ ├── ft_lstsize.c │ ├── ft_lstclear.c │ ├── ft_lstnew.c │ └── ft_lstmap.c ├── str │ ├── ft_tolower.c │ ├── ft_toupper.c │ ├── ft_strlen.c │ ├── ft_striteri.c │ ├── ft_strcmp.c │ ├── ft_strdup.c │ ├── ft_strlcpy.c │ ├── ft_strncmp.c │ ├── ft_strrchr.c │ ├── ft_strchr.c │ ├── ft_strtrim.c │ ├── ft_strmapi.c │ ├── ft_strnstr.c │ ├── ft_substr.c │ ├── ft_strjoin.c │ ├── ft_atoi.c │ ├── ft_strlcat.c │ ├── ft_itoa.c │ └── ft_split.c ├── get_next_line │ ├── get_next_line_utils.c │ └── get_next_line.c └── printf │ └── ft_printf.c ├── Makefile └── include └── libft.h /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "stdio.h": "c" 4 | } 5 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DinoLib 2 | Libft, but better. 3 | 4 | **The DinoLib received commits from :** 5 | - 42 Le Havre 6 | - 19 Bruxelles 7 | -------------------------------------------------------------------------------- /src/is/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 15:44:21 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:21:45 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isascii(int ch) 16 | { 17 | return (ch >= 0 && ch <= 127); 18 | } 19 | -------------------------------------------------------------------------------- /src/is/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 15:20:49 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:08:52 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isdigit(int ch) 16 | { 17 | return (ch >= '0' && ch <= '9'); 18 | } 19 | -------------------------------------------------------------------------------- /src/is/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 15:45:55 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:07:29 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isprint(int ch) 16 | { 17 | return (ch >= 32 && ch <= 126); 18 | } 19 | -------------------------------------------------------------------------------- /src/is/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 15:42:40 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:07:15 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalnum(int ch) 16 | { 17 | return (ft_isalpha(ch) || ft_isdigit(ch)); 18 | } 19 | -------------------------------------------------------------------------------- /src/put/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:16:37 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 18:59:46 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_putchar_fd(char ch, int fd) 16 | { 17 | return (write(fd, &ch, 1)); 18 | } 19 | -------------------------------------------------------------------------------- /src/mem/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 16:18:00 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:14:35 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *pointer, size_t size) 16 | { 17 | ft_memset(pointer, '\0', size); 18 | } 19 | -------------------------------------------------------------------------------- /src/put/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:17:55 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 19:29:21 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_putstr_fd(char *str, int fd) 16 | { 17 | return (write(fd, str, ft_strlen(str))); 18 | } 19 | -------------------------------------------------------------------------------- /src/is/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 15:41:40 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:07:12 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalpha(int ch) 16 | { 17 | return ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')); 18 | } 19 | -------------------------------------------------------------------------------- /src/lst/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:31:36 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:19:41 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **lst, t_list *new) 16 | { 17 | new->next = *lst; 18 | *lst = new; 19 | } 20 | -------------------------------------------------------------------------------- /src/lst/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:44:21 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:21:30 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void *)) 16 | { 17 | del(lst->content); 18 | free(lst); 19 | } 20 | -------------------------------------------------------------------------------- /src/str/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 20:58:21 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:15:55 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_tolower(int ch) 16 | { 17 | if (ch >= 'A' && ch <= 'Z') 18 | ch += 32; 19 | return (ch); 20 | } 21 | -------------------------------------------------------------------------------- /src/str/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 20:56:06 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:15:58 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_toupper(int ch) 16 | { 17 | if (ch >= 'a' && ch <= 'z') 18 | ch -= 32; 19 | return (ch); 20 | } 21 | -------------------------------------------------------------------------------- /src/put/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:19:36 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 18:59:50 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_putendl_fd(char *str, int fd) 16 | { 17 | return (ft_putstr_fd(str, fd) + ft_putchar_fd('\n', fd)); 18 | } 19 | -------------------------------------------------------------------------------- /src/str/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 19:25:39 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:18:40 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlen(const char *str) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | i++; 22 | return (i); 23 | } 24 | -------------------------------------------------------------------------------- /src/lst/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:51:28 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:19:19 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | while (lst) 18 | { 19 | f(lst->content); 20 | lst = lst->next; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/lst/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:39:29 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:12:46 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | if (*lst) 18 | ft_lstlast(*lst)->next = new; 19 | else 20 | *lst = new; 21 | } 22 | -------------------------------------------------------------------------------- /src/lst/ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:37:08 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:13:12 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | if (!lst) 18 | return (NULL); 19 | while (lst->next) 20 | lst = lst->next; 21 | return (lst); 22 | } 23 | -------------------------------------------------------------------------------- /src/lst/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:35:24 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:13:27 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int result; 18 | 19 | result = 0; 20 | while (lst) 21 | { 22 | lst = lst->next; 23 | result++; 24 | } 25 | return (result); 26 | } 27 | -------------------------------------------------------------------------------- /src/str/ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:13:37 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:20:18 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_striteri(char *str, void (*f)(unsigned int, char *)) 16 | { 17 | unsigned int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | f(i, &str[i]); 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/mem/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 19:21:36 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:07:07 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t count, size_t size) 16 | { 17 | void *result; 18 | 19 | result = malloc(count * size); 20 | if (result) 21 | ft_bzero(result, count * size); 22 | return (result); 23 | } 24 | -------------------------------------------------------------------------------- /src/lst/ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:45:53 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:16:29 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void *)) 16 | { 17 | t_list *tmp; 18 | 19 | while (*lst) 20 | { 21 | tmp = (*lst)->next; 22 | ft_lstdelone(*lst, del); 23 | *lst = tmp; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/mem/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 16:06:42 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:14:35 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *pointer, int value, size_t size) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < size) 21 | *(unsigned char *)(pointer + i++) = (unsigned char)value; 22 | return (pointer); 23 | } 24 | -------------------------------------------------------------------------------- /src/lst/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:29:40 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:16:37 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *new; 18 | 19 | new = malloc(sizeof(t_list)); 20 | if (!new) 21 | return (NULL); 22 | new->content = content; 23 | new->next = NULL; 24 | return (new); 25 | } 26 | -------------------------------------------------------------------------------- /src/str/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/01/03 19:33:50 by jcario #+# #+# */ 9 | /* Updated: 2024/01/03 19:41:51 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strcmp(const char *str1, const char *str2) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (str1[i] && str2[i] && str1[i] == str2[i]) 21 | i++; 22 | return ((unsigned char)str1[i] - (unsigned char)str2[i]); 23 | } 24 | -------------------------------------------------------------------------------- /src/put/ft_putunbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putunbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 19:19:15 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 19:21:09 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_putunbr_fd(unsigned int n, int fd) 16 | { 17 | if (n >= 10) 18 | return (ft_putnbr_fd(n / 10, fd) + ft_putnbr_fd(n % 10, fd)); 19 | else if (n < 10) 20 | { 21 | ft_putchar_fd(n + '0', fd); 22 | return (1); 23 | } 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /src/str/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 21:57:39 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:15:07 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(char *str) 16 | { 17 | char *result; 18 | int len; 19 | 20 | len = ft_strlen(str); 21 | result = malloc((len + 1) * sizeof(char)); 22 | if (!result) 23 | return (NULL); 24 | ft_strlcpy(result, str, len + 1); 25 | return (result); 26 | } 27 | -------------------------------------------------------------------------------- /src/str/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 20:01:20 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 14:36:09 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcpy(char *dst, const char *src, size_t size) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (src[i] && i < size - 1 && size) 21 | { 22 | dst[i] = src[i]; 23 | i++; 24 | } 25 | if (size) 26 | dst[i] = '\0'; 27 | return (ft_strlen(src)); 28 | } 29 | -------------------------------------------------------------------------------- /src/mem/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 19:04:52 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:22:31 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memchr(const void *ptr, int search, size_t size) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < size) 21 | { 22 | if (*(unsigned char *)(ptr + i) == (unsigned char)search) 23 | return ((void *)(ptr + i)); 24 | i++; 25 | } 26 | return (NULL); 27 | } 28 | -------------------------------------------------------------------------------- /src/mem/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 16:22:59 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 14:28:24 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t size) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (dst == src) 21 | return (dst); 22 | while (i < size) 23 | { 24 | *(unsigned char *)(dst + i) = *(unsigned char *)(src + i); 25 | i++; 26 | } 27 | return (dst); 28 | } 29 | -------------------------------------------------------------------------------- /src/str/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 21:15:57 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 15:15:35 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(char *str1, char *str2, size_t size) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (str1[i] == str2[i] && i < size && str1[i] && str2[i]) 21 | i++; 22 | if (i == size) 23 | return (0); 24 | return ((unsigned char)str1[i] - (unsigned char)str2[i]); 25 | } 26 | -------------------------------------------------------------------------------- /src/str/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 21:03:42 by jcario #+# #+# */ 9 | /* Updated: 2023/12/08 21:15:17 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(char *str, int search) 16 | { 17 | int i; 18 | 19 | i = ft_strlen(str); 20 | if (!(unsigned char)search) 21 | return (str + ft_strlen(str)); 22 | while (i-- >= 0) 23 | if (str[i] == (unsigned char)search) 24 | return (&str[i]); 25 | return (NULL); 26 | } 27 | -------------------------------------------------------------------------------- /src/str/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 21:01:44 by jcario #+# #+# */ 9 | /* Updated: 2024/01/03 18:11:01 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *str, int search) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if (str[i] == (char)search) 23 | return ((char *)(str + i)); 24 | i++; 25 | } 26 | if (search == '\0') 27 | return ((char *)(str + i)); 28 | return (NULL); 29 | } 30 | -------------------------------------------------------------------------------- /src/str/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 22:30:04 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:15:45 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strtrim(char const *str, char const *set) 16 | { 17 | int start; 18 | int end; 19 | 20 | start = 0; 21 | end = ft_strlen(str) - 1; 22 | while (ft_strchr((char *)set, str[start])) 23 | start++; 24 | while (ft_strchr((char *)set, str[end])) 25 | end--; 26 | return (ft_substr(str, start, (end - start) + 1)); 27 | } 28 | -------------------------------------------------------------------------------- /src/str/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 02:45:58 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:15:29 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *str, char (*f)(unsigned int, char)) 16 | { 17 | unsigned int i; 18 | char *result; 19 | 20 | result = ft_calloc((ft_strlen(str) + 1), sizeof(char)); 21 | if (!result) 22 | return (NULL); 23 | i = 0; 24 | while (str[i]) 25 | { 26 | result[i] = f(i, str[i]); 27 | i++; 28 | } 29 | return (result); 30 | } 31 | -------------------------------------------------------------------------------- /src/put/ft_puthexa_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_puthexa_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 19:01:05 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 19:17:30 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_puthexa_fd(unsigned long n, int fd, int up) 16 | { 17 | char hexa[16] = "0123456789abcdef"; 18 | 19 | if (n >= 16) 20 | return (ft_puthexa_fd(n / 16, fd, up) + ft_puthexa_fd(n % 16, fd, up)); 21 | else if (n < 16) 22 | { 23 | if (up) 24 | return (ft_putchar_fd(ft_toupper(hexa[n]), fd)); 25 | else 26 | return (ft_putchar_fd(hexa[n], fd)); 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /src/mem/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 19:10:36 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 14:38:38 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_memcmp(const void *ptr1, const void *ptr2, size_t len) 16 | { 17 | size_t i; 18 | unsigned char *uc_ptr_1; 19 | unsigned char *uc_ptr_2; 20 | 21 | i = 0; 22 | uc_ptr_1 = (unsigned char *)ptr1; 23 | uc_ptr_2 = (unsigned char *)ptr2; 24 | while (i < len) 25 | { 26 | if (uc_ptr_1[i] != uc_ptr_2[i]) 27 | return (uc_ptr_1[i] - uc_ptr_2[i]); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /src/lst/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:52:49 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:14:35 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 16 | { 17 | t_list *head; 18 | t_list *new; 19 | 20 | head = NULL; 21 | while (lst) 22 | { 23 | new = ft_lstnew(NULL); 24 | if (!new) 25 | { 26 | ft_lstclear(&head, del); 27 | return (NULL); 28 | } 29 | new->content = f(lst->content); 30 | ft_lstadd_back(&head, new); 31 | lst = lst->next; 32 | } 33 | return (head); 34 | } 35 | -------------------------------------------------------------------------------- /src/str/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 21:23:28 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 14:45:07 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(char *str, char *search, size_t size) 16 | { 17 | size_t i; 18 | size_t j; 19 | size_t len_search; 20 | 21 | i = 0; 22 | len_search = ft_strlen(search); 23 | if (!len_search) 24 | return (str); 25 | while (str[i] && i < size) 26 | { 27 | j = 0; 28 | while (str[i + j] == search[j] && i + j < size && str[i + j]) 29 | j++; 30 | if (j == len_search) 31 | return (&str[i]); 32 | i++; 33 | } 34 | return (NULL); 35 | } 36 | -------------------------------------------------------------------------------- /src/str/ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 22:02:17 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:15:52 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_substr(char const *src, unsigned int start, size_t size) 16 | { 17 | char *result; 18 | size_t len_src; 19 | 20 | len_src = ft_strlen(src); 21 | if (!len_src || len_src < start) 22 | return (ft_strdup("")); 23 | if (len_src - start < size) 24 | size = len_src - start; 25 | result = malloc((size + 1) * sizeof(char)); 26 | if (!result) 27 | return (NULL); 28 | ft_strlcpy(result, src + start, size + 1); 29 | return (result); 30 | } 31 | -------------------------------------------------------------------------------- /src/str/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 22:14:34 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 15:25:17 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | char *ft_strjoin(char const *str1, char const *str2) 17 | { 18 | char *result; 19 | size_t len_str1; 20 | size_t len_str2; 21 | 22 | len_str1 = ft_strlen(str1); 23 | len_str2 = ft_strlen(str2); 24 | result = malloc((len_str1 + len_str2 + 1) * sizeof(char)); 25 | if (!result) 26 | return (NULL); 27 | ft_strlcpy(result, str1, len_str1 + 1); 28 | ft_strlcat(result, str2, len_str1 + len_str2 + 1); 29 | return (result); 30 | } 31 | -------------------------------------------------------------------------------- /src/str/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 21:39:29 by jcario #+# #+# */ 9 | /* Updated: 2023/12/08 21:57:06 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | int ft_atoi(const char *str) 17 | { 18 | int i; 19 | int minus; 20 | int result; 21 | 22 | i = 0; 23 | minus = 1; 24 | result = 0; 25 | while ((str[i] >= '\t' && str[i] <= '\r') || str[i] == ' ') 26 | i++; 27 | if (str[i] == '+' || str[i] == '-') 28 | if (str[i++] == '-') 29 | minus = -1; 30 | while (ft_isdigit(str[i])) 31 | { 32 | result *= 10; 33 | result += str[i++] - '0'; 34 | } 35 | return (result * minus); 36 | } 37 | -------------------------------------------------------------------------------- /src/mem/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 16:29:31 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 14:29:07 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t size) 16 | { 17 | long i; 18 | 19 | if (dst == src) 20 | return (dst); 21 | if (dst > src) 22 | { 23 | i = size - 1; 24 | while (i >= 0) 25 | { 26 | *(unsigned char *)(dst + i) = *(unsigned char *)(src + i); 27 | i--; 28 | } 29 | } 30 | else 31 | { 32 | i = 0; 33 | while ((size_t)i < size) 34 | { 35 | *(unsigned char *)(dst + i) = *(unsigned char *)(src + i); 36 | i++; 37 | } 38 | } 39 | return (dst); 40 | } 41 | -------------------------------------------------------------------------------- /src/str/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 20:19:55 by jcario #+# #+# */ 9 | /* Updated: 2023/12/08 20:54:43 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t size) 16 | { 17 | size_t i; 18 | size_t j; 19 | size_t dst_size; 20 | 21 | i = 0; 22 | j = 0; 23 | dst_size = ft_strlen(dst); 24 | if (!size) 25 | return (ft_strlen(src)); 26 | while (dst[i]) 27 | i++; 28 | while (src[j] && i < size - 1) 29 | dst[i++] = src[j++]; 30 | if (i < size) 31 | dst[i] = '\0'; 32 | if (dst_size > size) 33 | return (ft_strlen(src) + size); 34 | else 35 | return (dst_size + ft_strlen(src)); 36 | } 37 | -------------------------------------------------------------------------------- /src/put/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/09 03:20:26 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 18:58:45 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | int ft_putnbr_fd(int n, int fd) 17 | { 18 | if (n <= -10) 19 | { 20 | ft_putchar_fd('-', fd); 21 | return (1 + ft_putnbr_fd(-(n / 10), fd) + ft_putnbr_fd(-(n % 10), fd)); 22 | } 23 | else if (n < 0) 24 | { 25 | ft_putchar_fd('-', fd); 26 | return (1 + ft_putnbr_fd(-n, fd)); 27 | } 28 | else if (n >= 10) 29 | return (ft_putnbr_fd(n / 10, fd) + ft_putnbr_fd(n % 10, fd)); 30 | else if (n < 10) 31 | { 32 | ft_putchar_fd(n + '0', fd); 33 | return (1); 34 | } 35 | return (0); 36 | } -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC = cc 2 | CFLAGS = -Wall -Wextra -Werror -Iinclude -g 3 | 4 | FILES = is/ft_isdigit is/ft_isalnum is/ft_isalpha is/ft_isascii is/ft_isprint \ 5 | mem/ft_memset mem/ft_bzero mem/ft_memcpy mem/ft_memmove mem/ft_memchr mem/ft_memcmp mem/ft_calloc \ 6 | str/ft_strlen str/ft_strlcpy str/ft_strlcat str/ft_toupper str/ft_tolower str/ft_strchr str/ft_strrchr str/ft_strncmp str/ft_strnstr str/ft_atoi \ 7 | str/ft_strdup str/ft_strcmp str/ft_substr str/ft_strjoin str/ft_strtrim str/ft_split str/ft_itoa str/ft_strmapi str/ft_striteri \ 8 | put/ft_putchar_fd put/ft_putstr_fd put/ft_putendl_fd put/ft_putnbr_fd put/ft_puthexa_fd put/ft_putunbr_fd \ 9 | lst/ft_lstnew lst/ft_lstadd_back lst/ft_lstadd_front lst/ft_lstclear lst/ft_lstdelone lst/ft_lstiter lst/ft_lstmap lst/ft_lstsize lst/ft_lstlast \ 10 | printf/ft_printf get_next_line/get_next_line_utils get_next_line/get_next_line 11 | 12 | OBJ_DIR = obj/ 13 | SRCS = $(addprefix src/, $(addsuffix .c, $(FILES))) 14 | OBJS = $(addprefix $(OBJ_DIR), $(addsuffix .o, $(FILES))) 15 | 16 | NAME = libft.a 17 | 18 | .PHONY = all clean fclean re 19 | 20 | all: $(OBJS) 21 | @echo "\033[32m✔ Compilating DinoLib files...\033[37m" 22 | @ar -rcs $(NAME) $(OBJS) 23 | @echo "\033[32m✔ DinoLib created.\033[37m" 24 | 25 | clean: 26 | @echo "\033[31m✔ Deleting DinoLib...\033[37m" 27 | @rm -rf $(OBJ_DIR) 28 | 29 | fclean: clean 30 | @rm -rf $(NAME) 31 | 32 | re: fclean all 33 | 34 | obj/%.o: src/%.c 35 | @mkdir -p $(dir $@) 36 | @$(CC) $(CFLAGS) -c $< -o $@ 37 | 38 | # $(OBJ_DIR): 39 | # @mkdir -p $@ 40 | -------------------------------------------------------------------------------- /src/get_next_line/get_next_line_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/11/06 14:46:10 by jcario #+# #+# */ 9 | /* Updated: 2024/01/03 19:00:09 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoin_modified(char *s1, char *s2) 16 | { 17 | char *result; 18 | int i; 19 | int j; 20 | 21 | i = -1; 22 | j = 0; 23 | if (s2 == NULL) 24 | return (NULL); 25 | if (s1 == NULL) 26 | { 27 | s1 = malloc(sizeof(char)); 28 | if (s1 == NULL) 29 | return (NULL); 30 | s1[0] = '\0'; 31 | } 32 | result = malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char)); 33 | if (!result) 34 | return (NULL); 35 | while (s1[++i]) 36 | result[i] = s1[i]; 37 | while (s2[j]) 38 | result[i++] = s2[j++]; 39 | result[i] = '\0'; 40 | free(s1); 41 | return (result); 42 | } 43 | -------------------------------------------------------------------------------- /src/str/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 23:23:22 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:17:59 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | char *ft_itoa(int nb) 17 | { 18 | char *result; 19 | int len; 20 | long nb_cpy; 21 | 22 | len = (nb < 0) * 2 + (nb >= 0); 23 | nb_cpy = ((long)(nb * (nb < 0)) *-1) + (nb * (nb > 0)); 24 | while (nb_cpy >= 10 || nb_cpy <= -10) 25 | { 26 | len++; 27 | nb_cpy /= 10; 28 | } 29 | result = ft_calloc(1 + len--, sizeof(char)); 30 | if (!result) 31 | return (NULL); 32 | nb_cpy = nb; 33 | if (nb < 0) 34 | nb_cpy = (long)(nb) *-1; 35 | while (len >= 0) 36 | { 37 | result[len--] = (nb_cpy % 10) + '0'; 38 | nb_cpy /= 10; 39 | } 40 | if (nb < 0) 41 | result[0] = '-'; 42 | return (result); 43 | } 44 | -------------------------------------------------------------------------------- /src/str/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 22:36:32 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 04:21:02 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | static int len_split(char const *str, char c) 17 | { 18 | int i; 19 | int result; 20 | 21 | i = 0; 22 | result = 0; 23 | while (str[i]) 24 | { 25 | while (str[i] && str[i] == c) 26 | i++; 27 | if (str[i]) 28 | result++; 29 | while (str[i] && str[i] != c) 30 | i++; 31 | } 32 | return (result); 33 | } 34 | 35 | static int len_word(char const *str, char c, int start) 36 | { 37 | int result; 38 | 39 | result = 0; 40 | while (str[start + result] && str[start + result] != c) 41 | result++; 42 | return (result); 43 | } 44 | 45 | static char **free_split(char **split, int start) 46 | { 47 | while (start >= 0) 48 | free(split[start--]); 49 | free(split); 50 | return (NULL); 51 | } 52 | 53 | char **ft_split(char const *str, char c) 54 | { 55 | int i; 56 | int j; 57 | char **result; 58 | 59 | result = malloc((len_split(str, c) + 1) * sizeof(char *)); 60 | if (!result) 61 | return (NULL); 62 | i = 0; 63 | j = 0; 64 | while (str[j]) 65 | { 66 | while (str[j] && str[j] == c) 67 | j++; 68 | if (!str[j]) 69 | break ; 70 | result[i++] = ft_substr(str, j, len_word(str, c, j)); 71 | if (!result[i - 1]) 72 | return (free_split(result, i - 2)); 73 | while (str[j] && str[j] != c) 74 | j++; 75 | } 76 | result[i] = NULL; 77 | return (result); 78 | } 79 | -------------------------------------------------------------------------------- /src/printf/ft_printf.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/10/20 16:13:06 by jcario #+# #+# */ 9 | /* Updated: 2023/12/09 19:36:52 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int handle_ptr(void *ptr) 16 | { 17 | if (!ptr) 18 | return (ft_putstr_fd("(nil)", 1)); 19 | return (ft_puthexa_fd((unsigned long)ptr, 1, FALSE)); 20 | } 21 | 22 | int ft_put_var(char type, va_list args) 23 | { 24 | if (type == 'c') 25 | return (ft_putchar_fd((char)va_arg(args, int), 1)); 26 | if (type == 's') 27 | return (ft_putstr_fd((char *)va_arg(args, char *), 1)); 28 | if (type == 'p') 29 | return (handle_ptr((void *)va_arg(args, void *))); 30 | if (type == 'd') 31 | return (ft_putnbr_fd((int)va_arg(args, int), 1)); 32 | if (type == 'i') 33 | return (ft_putnbr_fd((int)va_arg(args, int), 1)); 34 | if (type == 'u') 35 | return (ft_putunbr_fd((unsigned int)va_arg(args, unsigned int), 1)); 36 | if (type == 'x') 37 | return (ft_puthexa_fd((int)va_arg(args, int), 1, FALSE)); 38 | if (type == 'X') 39 | return (ft_puthexa_fd((int)va_arg(args, int), 1, TRUE)); 40 | if (type == '%') 41 | return (ft_putchar_fd('%', 1)); 42 | return (0); 43 | } 44 | 45 | int ft_printf(const char *str, ...) 46 | { 47 | int i; 48 | va_list args; 49 | int count; 50 | 51 | i = 0; 52 | count = 0; 53 | va_start(args, str); 54 | while (str[i]) 55 | { 56 | if (str[i] == '%' && str[i + 1]) 57 | { 58 | i++; 59 | count += ft_put_var(str[i], args); 60 | i++; 61 | } 62 | if (str[i] && str[i] != '%') 63 | { 64 | ft_putchar_fd(str[i], 1); 65 | count++; 66 | i++; 67 | } 68 | } 69 | va_end(args); 70 | return (count); 71 | } 72 | -------------------------------------------------------------------------------- /src/get_next_line/get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/10/24 15:07:19 by jcario #+# #+# */ 9 | /* Updated: 2024/01/03 18:17:11 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *read_to_buff(int fd, char *str) 16 | { 17 | char *buffer; 18 | int rd; 19 | 20 | buffer = malloc((BUFFER_SIZE + 1) * sizeof(char)); 21 | if (!buffer) 22 | return (NULL); 23 | rd = 1; 24 | while (!ft_strchr(str, '\n') && rd != 0) 25 | { 26 | rd = read(fd, buffer, BUFFER_SIZE); 27 | if (rd == -1) 28 | { 29 | free(buffer); 30 | return (NULL); 31 | } 32 | buffer[rd] = '\0'; 33 | str = ft_strjoin_modified(str, buffer); 34 | if (str == NULL) 35 | { 36 | free(buffer); 37 | return (NULL); 38 | } 39 | } 40 | free(buffer); 41 | return (str); 42 | } 43 | 44 | char *get_line_buff(char *buff) 45 | { 46 | int i; 47 | char *result; 48 | 49 | i = 0; 50 | if (!buff || !buff[i]) 51 | return (NULL); 52 | while (buff[i] && buff[i] != '\n') 53 | i++; 54 | result = malloc((i + 2) * sizeof(char)); 55 | if (!result) 56 | return (NULL); 57 | i = 0; 58 | while (buff[i] && buff[i] != '\n') 59 | { 60 | result[i] = buff[i]; 61 | i++; 62 | } 63 | if (buff[i] == '\n') 64 | result[i++] = '\n'; 65 | result[i] = '\0'; 66 | return (result); 67 | } 68 | 69 | char *update_buff(char *buff) 70 | { 71 | int i; 72 | int j; 73 | char *result; 74 | 75 | i = 0; 76 | while (buff[i] && buff[i] != '\n') 77 | i++; 78 | if (!buff[i]) 79 | { 80 | free(buff); 81 | return (NULL); 82 | } 83 | result = malloc((ft_strlen(buff) - i + 1) * sizeof(char)); 84 | if (!result) 85 | { 86 | free(buff); 87 | return (NULL); 88 | } 89 | i++; 90 | j = 0; 91 | while (buff[i]) 92 | result[j++] = buff[i++]; 93 | result[j] = '\0'; 94 | free(buff); 95 | return (result); 96 | } 97 | 98 | char *get_next_line(int fd) 99 | { 100 | static char *buff = NULL; 101 | char *result; 102 | 103 | if (fd < 0 || BUFFER_SIZE <= 0) 104 | return (NULL); 105 | if (buff == NULL) 106 | { 107 | buff = malloc(1); 108 | if (buff == NULL) 109 | return (NULL); 110 | buff[0] = '\0'; 111 | } 112 | buff = read_to_buff(fd, buff); 113 | if (!buff) 114 | { 115 | free(buff); 116 | return (NULL); 117 | } 118 | result = get_line_buff(buff); 119 | buff = update_buff(buff); 120 | return (result); 121 | } 122 | -------------------------------------------------------------------------------- /include/libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcario +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/12/08 15:19:23 by jcario #+# #+# */ 9 | /* Updated: 2024/01/03 19:44:02 by jcario ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | # define TRUE 1 21 | # define FALSE 0 22 | 23 | # ifndef BUFFER_SIZE 24 | # define BUFFER_SIZE 1 25 | # endif 26 | 27 | typedef struct s_list 28 | { 29 | void *content; 30 | struct s_list *next; 31 | } t_list; 32 | 33 | /* ================================== IS =================================== */ 34 | 35 | /** 36 | @brief Check if the character given is a digit. 37 | @param ch A character. 38 | @return 1 if the character is a digit, otherwise 0. 39 | */ 40 | int ft_isdigit(int ch); 41 | 42 | /** 43 | @brief Check if the character given is a letter. 44 | @param ch A character. 45 | @return 1 if the character is a letter, otherwise 0. 46 | */ 47 | int ft_isalpha(int ch); 48 | 49 | /** 50 | @brief Check if the character given is alphanumeric. 51 | @param ch A character. 52 | @return 1 if the character is alphanumeric, otherwise 0. 53 | */ 54 | int ft_isalnum(int ch); 55 | 56 | /** 57 | @brief Check if the character given is in the ASCII table. 58 | @param ch A character. 59 | @return 1 if the character is ASCII, otherwise 0. 60 | */ 61 | int ft_isascii(int ch); 62 | 63 | /** 64 | @brief Check if the character given is printable. 65 | @param ch A character. 66 | @return 1 if the character is printable, otherwise 0. 67 | */ 68 | int ft_isprint(int ch); 69 | 70 | /* ================================== MEM ================================== */ 71 | 72 | /** 73 | @brief Sets 'size' bytes of the memory to 'value'. 74 | @param pointer A pointer to the memory. 75 | @param value An byte. 76 | @param size A size. 77 | @return A pointer to the memory set. 78 | */ 79 | void *ft_memset(void *pointer, int value, size_t size); 80 | 81 | /** 82 | @brief Sets 'size' bytes of the memory to zero. 83 | @param pointer A pointer. 84 | @param size A size. 85 | @return A pointer to the memory that had been set. 86 | */ 87 | void ft_bzero(void *pointer, size_t size); 88 | 89 | /** 90 | @brief Copy the memory from a source to a destination. 91 | @param dst A pointer to the destination. 92 | @param src A pointer to the source. 93 | @param size A size. 94 | @return A pointer to the memory that had been copied. 95 | */ 96 | void *ft_memcpy(void *dst, const void *src, size_t size); 97 | 98 | /** 99 | @brief Copy the memory from a source to a destination, 100 | securizing the potentials overlaps. 101 | @param dst A pointer to the destination. 102 | @param src A pointer to the source. 103 | @param size A size. 104 | @return A pointer to the memory that had been moved. 105 | */ 106 | void *ft_memmove(void *dst, const void *src, size_t size); 107 | 108 | /** 109 | @brief Search for a given byte in a memory area. 110 | @param ptr A pointer. 111 | @param search A byte. 112 | @param size A size. 113 | @return A pointer to the memory found, NULL otherwise. 114 | */ 115 | void *ft_memchr(const void *ptr, int search, size_t size); 116 | 117 | /** 118 | @brief Compare two memory areas. 119 | @param ptr1 A pointer. 120 | @param ptr2 A pointer. 121 | @param size A size. 122 | @return 0 if the memory areas are identical, otherwise the difference between them. 123 | */ 124 | int ft_memcmp(const void *ptr1, const void *ptr2, size_t size); 125 | 126 | /** 127 | @brief Allocate a memory area and set all its bytes to zero. 128 | @param count A pointer. 129 | @param size A size. 130 | @return A pointer to the memory that had been allocated. 131 | */ 132 | void *ft_calloc(size_t count, size_t size); 133 | 134 | /* ================================== STR ================================== */ 135 | 136 | /** 137 | @brief Evaluates the size of a string. 138 | @param str A string. 139 | @return The size of the string. 140 | */ 141 | size_t ft_strlen(const char *str); 142 | 143 | /** 144 | @brief Copy a source string to a destination buffer. 145 | @param dst A string. 146 | @param src A string. 147 | @param size A size. 148 | @return The size of the string the function tried to create. 149 | */ 150 | size_t ft_strlcpy(char *dst, const char *src, size_t size); 151 | 152 | /** 153 | @brief Concatenate a source string to a destination buffer. 154 | @param dst A string. 155 | @param src A string. 156 | @param size A size. 157 | @return The size of the string the function tried to create. 158 | */ 159 | size_t ft_strlcat(char *dst, const char *src, size_t size); 160 | 161 | /** 162 | @brief Transform an uppercase to a lowercase. 163 | @param ch A character. 164 | @return A character in lowercase if the character given was a letter, 165 | otherwise the original character. 166 | */ 167 | int ft_tolower(int ch); 168 | 169 | /** 170 | @brief Transform a lowercase to an uppercase. 171 | @param ch A character. 172 | @return A character in uppercase if the character given was a letter, 173 | otherwise the original character. 174 | */ 175 | int ft_toupper(int ch); 176 | 177 | /** 178 | @brief Search for a specified character in a string. 179 | @param str A string. 180 | @param search A character. 181 | @return A pointer to the first occurence of the character in the string. 182 | */ 183 | char *ft_strchr(const char *str, int search); 184 | 185 | /** 186 | @brief Compare two strings. 187 | @param str1 A string. 188 | @param str2 A string. 189 | @return 0 if the string are identical, otherwise the differences between them. 190 | */ 191 | int ft_strcmp(const char *str1, const char *str2); 192 | 193 | /** 194 | @brief Search for a specified character in a string. 195 | @param str A string. 196 | @param search A character. 197 | @return A pointer to the last occurence of the character in the string. 198 | */ 199 | char *ft_strrchr(char *str, int search); 200 | 201 | /** 202 | @brief Compare two strings on a given size. 203 | @param str1 A string. 204 | @param str2 A string. 205 | @param size A size. 206 | @return 0 if the string are identical, otherwise the differences between them. 207 | */ 208 | int ft_strncmp(char *str1, char *str2, size_t size); 209 | 210 | /** 211 | @brief Search for a given string in another string. 212 | @param str A string. 213 | @param search A string. 214 | @param size A size. 215 | @return A pointer to the start of the string found in the source string, 216 | otherwise NULL. 217 | */ 218 | char *ft_strnstr(char *str, char *search, size_t size); 219 | 220 | /** 221 | @brief Transform a string into an int. 222 | @param str A string. 223 | @return An integer corresponding to the first digits of the string. 224 | If the string has more than one sign, or has letter before the digits, 225 | it return 0. The string can contain multiples whitespaces before the digits. 226 | */ 227 | int ft_atoi(const char *str); 228 | 229 | /** 230 | @brief Duplicate a given string. 231 | @param str A string. 232 | @return A pointer to a new string allocated in the memory that is identical 233 | to the source. 234 | */ 235 | char *ft_strdup(char *str); 236 | 237 | /** 238 | @brief Create a new string substracted from a given string at a given index. 239 | @param str A string. 240 | @param start An integer. 241 | @param len A size. 242 | @return The new string substracted from the source at the index start. 243 | */ 244 | char *ft_substr(char const *src, unsigned int start, size_t len); 245 | 246 | /** 247 | @brief Merge two strings in a new one. 248 | @param str1 A string. 249 | @param str2 A string. 250 | @return A pointer to the new string. 251 | */ 252 | char *ft_strjoin(char const *str1, char const *str2); 253 | 254 | /** 255 | @brief Trim all the characters included in a set from the start and the end of 256 | a string. 257 | @param str A string. 258 | @param set A string. 259 | @return A new string where the characters included in 'set' had been cut from 260 | the start and the end. 261 | */ 262 | char *ft_strtrim(char const *str, char const *set); 263 | 264 | /** 265 | @brief Split a string in multiples parts, given a separator. 266 | @param str A string. 267 | @param c A character. 268 | @return 0 if the string are identical, otherwise the differences between them. 269 | */ 270 | char **ft_split(char const *str, char c); 271 | 272 | /** 273 | @brief Transform an integer into a string. 274 | @param nb An integer. 275 | @return A new string allocated containing the digits that correspond to 276 | the integer given. 277 | */ 278 | char *ft_itoa(int nb); 279 | 280 | /** 281 | @brief Create a new string where each character from the old string is passed 282 | trough a function. 283 | @param str A string. 284 | @param f A function. 285 | @return A pointer to the new string. 286 | */ 287 | char *ft_strmapi(char const *str, char (*f)(unsigned int, char)); 288 | 289 | /** 290 | @brief Iterate a function on each character of a given string. 291 | @param str A string. 292 | @param f A function. 293 | */ 294 | void ft_striteri(char *str, void (*f)(unsigned int, char *)); 295 | 296 | /* ================================== PUT ================================== */ 297 | 298 | /** 299 | @brief Print a character on a defined file descriptor. 300 | @param ch A character. 301 | @param fd A file descriptor. 302 | @return The number of characters that the function has printed, always 1. 303 | */ 304 | int ft_putchar_fd(char ch, int fd); 305 | 306 | /** 307 | @brief Print a string on a defined file descriptor. 308 | @param str A string. 309 | @param fd A file descriptor. 310 | @return The len of the string. 311 | */ 312 | int ft_putstr_fd(char *str, int fd); 313 | 314 | /** 315 | @brief Print a string on a defined file descriptor, and 316 | put an endline at the end. 317 | @param str A string. 318 | @param fd A file descriptor. 319 | @return The len of the string and of the endline (strlen + 1). 320 | */ 321 | int ft_putendl_fd(char *str, int fd); 322 | 323 | /** 324 | @brief Print an integer on a defined file descriptor. 325 | @param n An integer. 326 | @param fd A file descriptor. 327 | @return The number of character that the function has printed. 328 | */ 329 | int ft_putnbr_fd(int n, int fd); 330 | 331 | /** 332 | @brief Print an unsigned integer on a defined file descriptor. 333 | @param n An unsigned integer. 334 | @param fd A file descriptor. 335 | @return The number of character that the function has printed. 336 | */ 337 | int ft_putunbr_fd(unsigned int n, int fd); 338 | 339 | /** 340 | @brief Print an integer converted into hexadecimal on a defined file 341 | descriptor. If 'upper' is true, then it will print in uppercase, 342 | otherwise in lowercase. 343 | @param n An integer. 344 | @param fd A file descriptor. 345 | @param up A boolean. 346 | @return The number of character that the function has printed. 347 | */ 348 | int ft_puthexa_fd(unsigned long n, int fd, int upper); 349 | 350 | /* ================================== LST ================================== */ 351 | 352 | /** 353 | @brief Create a new node. 354 | @param content The content of the new node. 355 | @return A new node. 356 | */ 357 | t_list *ft_lstnew(void *content); 358 | 359 | /** 360 | @brief Add a new element at the front of a list. 361 | @param lst The first node of the list. 362 | @param new A node. 363 | */ 364 | void ft_lstadd_front(t_list **lst, t_list *new); 365 | 366 | /** 367 | @brief Evaluates the size of a list. 368 | @param lst The first node of the list. 369 | @return The size of the list. 370 | */ 371 | int ft_lstsize(t_list *lst); 372 | 373 | /** 374 | @brief Find the last node of a list. 375 | @param lst The first node of the list. 376 | @return The last node of the list. 377 | */ 378 | t_list *ft_lstlast(t_list *lst); 379 | 380 | /** 381 | @brief Add a new element at the back of a list. 382 | @param lst The first node of the list. 383 | @param new A node. 384 | */ 385 | void ft_lstadd_back(t_list **lst, t_list *new); 386 | 387 | /** 388 | @brief Delete the content of a node and free it from the memory. 389 | @param lst A node. 390 | @param del A function. 391 | */ 392 | void ft_lstdelone(t_list *lst, void (*del)(void *)); 393 | 394 | /** 395 | @brief Delete an entire list, freeing all the nodes from the memory. 396 | @param lst The first node of a list. 397 | @param del A function. 398 | */ 399 | void ft_lstclear(t_list **lst, void (*del)(void *)); 400 | 401 | /** 402 | @brief Iterate a function trough the contents of each node of a list. 403 | @param lst The first node of a list. 404 | @param f A function. 405 | */ 406 | void ft_lstiter(t_list *lst, void (*f)(void *)); 407 | 408 | /** 409 | @brief Create a new list where each node had been passed trough a function. 410 | @param lst The first node of a list. 411 | @param f A function. 412 | @param del A function to delete a node. 413 | @return A pointer to the first element of a new list. If there is an 414 | allocation error, all the nodes will be deleted with the del function 415 | then freed from the memory before ft_lstmap returns NULL. 416 | */ 417 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); 418 | 419 | /* ================================= UTILS ================================= */ 420 | 421 | /** 422 | @brief A reimplementation of printf, works with cspdixX%. 423 | @param str A string. 424 | @param variadic Variadic arguments. 425 | @return The number of character that the function has printed 426 | */ 427 | int ft_printf(const char *str, ...); 428 | 429 | /** 430 | @brief A modification of strjoin to fit the exigences of get_next_line. 431 | @param s1 A string. 432 | @param s2 A string. 433 | @return A string that join s1 and s2. 434 | */ 435 | char *ft_strjoin_modified(char *s1, char *s2); 436 | 437 | /** 438 | @brief Get the next line of a given file descriptor. 439 | @param fd A file descriptor. 440 | @return The next line of the given file descriptor. 441 | */ 442 | char *get_next_line(int fd); 443 | 444 | #endif 445 | --------------------------------------------------------------------------------