diff options
| author | Dominik Kaiser | 2024-06-24 16:58:46 +0200 |
|---|---|---|
| committer | GitHub | 2024-06-24 16:58:46 +0200 |
| commit | a28e57c6e0277a1d7346bec58cf557c52e337501 (patch) | |
| tree | 8710c1c12dfd9e6c52821944b0676ec15e5e20ae /lib/libft | |
| parent | f1349566aef0cb80ef8f4cdcf2795e38631ed820 (diff) | |
| download | minishell-a28e57c6e0277a1d7346bec58cf557c52e337501.tar.gz minishell-a28e57c6e0277a1d7346bec58cf557c52e337501.zip | |
Add libft
Diffstat (limited to 'lib/libft')
54 files changed, 2190 insertions, 0 deletions
diff --git a/lib/libft/Makefile b/lib/libft/Makefile new file mode 100644 index 0000000..3c2fb91 --- /dev/null +++ b/lib/libft/Makefile @@ -0,0 +1,87 @@ +NAME = libft.a +CC = cc +CFLAGS = -Wall -Wextra -Werror + +SRC = ft_atoi.c \ + ft_bzero.c \ + ft_calloc.c \ + ft_isalnum.c \ + ft_isalpha.c \ + ft_isascii.c \ + ft_isdigit.c \ + ft_isprint.c \ + ft_itoa.c \ + ft_memchr.c \ + ft_memcmp.c \ + ft_memcpy.c \ + ft_memmove.c \ + ft_memset.c \ + ft_putchar_fd.c \ + ft_putendl_fd.c \ + ft_putnbr_fd.c \ + ft_putstr_fd.c \ + ft_split.c \ + ft_strchr.c \ + ft_strdup.c \ + ft_striteri.c \ + ft_strjoin.c \ + ft_strlcat.c \ + ft_strlcpy.c \ + ft_strlen.c \ + ft_strmapi.c \ + ft_strncmp.c \ + ft_strnstr.c \ + ft_strrchr.c \ + ft_strtrim.c \ + ft_substr.c \ + ft_tolower.c \ + ft_toupper.c \ + ft_printf.c \ + ft_printnbr.c \ + ft_printhex.c \ + ft_printaddr.c \ + get_next_line.c \ + get_next_line_utils.c \ + ft_atol.c \ + ft_lstnew_bonus.c \ + ft_lstadd_front_bonus.c \ + ft_lstsize_bonus.c \ + ft_lstlast_bonus.c \ + ft_lstadd_back_bonus.c \ + ft_lstdelone_bonus.c \ + ft_lstclear_bonus.c \ + ft_lstiter_bonus.c \ + ft_lstmap_bonus.c + +OBJ_DIR := _obj +OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) + +all: $(NAME) + @: + +$(NAME): $(OBJ) + @ar rcs $(NAME) $(OBJ) + @echo "[$(NAME)] Created archive." + +$(OBJ_DIR)/%.o: %.c + @if [ ! -d "$(dir $@)" ]; then \ + mkdir -p $(dir $@); \ + fi + @$(CC) $(CFLAGS) $(HEADERS) -c $< -o $@ + @echo "[$(NAME)] Compiled $<." + +clean: + @if [ -d "$(OBJ_DIR)" ]; then \ + rm -rf $(OBJ_DIR); \ + echo "[$(NAME)] Removed object files."; \ + fi + +fclean: clean + @if [ -f "$(NAME)" ]; then \ + rm -f $(NAME); \ + echo "[$(NAME)] Removed archive."; \ + fi + +re: fclean all + +.PHONY: all clean fclean re diff --git a/lib/libft/ft_atoi.c b/lib/libft/ft_atoi.c new file mode 100644 index 0000000..90200fb --- /dev/null +++ b/lib/libft/ft_atoi.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 16:25:27 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:17:19 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_atoi(const char *str) +{ + int result; + int i; + int posneg; + + posneg = 1; + result = 0; + i = 0; + while ((str[i] >= '\t' && str[i] <= '\r') || str[i] == ' ') + { + i++; + } + if (str[i] == '-') + { + posneg = -1; + i++; + } + else if (str[i] == '+') + i++; + while (str[i] >= '0' && str[i] <= '9') + { + result = 10 * result + str[i] - '0'; + i++; + } + return (result * posneg); +} + +/* #include <stdio.h> */ +/* #include <stdlib.h> */ +/* int main() { */ +/* char str[] = " -42eaeouai"; */ +/* printf("atoi: %d\n", atoi(str)); */ +/* printf("ft_atoi: %d\n", ft_atoi(str)); */ +/* } */ diff --git a/lib/libft/ft_atol.c b/lib/libft/ft_atol.c new file mode 100644 index 0000000..ae47db0 --- /dev/null +++ b/lib/libft/ft_atol.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atol.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/26 16:18:28 by dkaiser #+# #+# */ +/* Updated: 2024/04/29 16:40:38 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +long ft_atol(const char *str) +{ + long result; + int i; + int posneg; + + posneg = 1; + result = 0; + i = 0; + while ((str[i] >= '\t' && str[i] <= '\r') || str[i] == ' ') + { + i++; + } + if (str[i] == '-') + { + posneg = -1; + i++; + } + else if (str[i] == '+') + i++; + while (str[i] >= '0' && str[i] <= '9') + { + result = 10 * result + str[i] - '0'; + i++; + } + return (result * posneg); +} diff --git a/lib/libft/ft_bzero.c b/lib/libft/ft_bzero.c new file mode 100644 index 0000000..78af51a --- /dev/null +++ b/lib/libft/ft_bzero.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/05 10:57:36 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:14:10 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + size_t i; + + i = 0; + while (i < n) + { + ((char *)s)[i] = 0; + i++; + } +} diff --git a/lib/libft/ft_calloc.c b/lib/libft/ft_calloc.c new file mode 100644 index 0000000..0dcc434 --- /dev/null +++ b/lib/libft/ft_calloc.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 19:45:56 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 15:34:06 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t count, size_t size) +{ + void *result; + + result = malloc(count * size); + if (result) + ft_bzero(result, count * size); + return (result); +} diff --git a/lib/libft/ft_isalnum.c b/lib/libft/ft_isalnum.c new file mode 100644 index 0000000..d705500 --- /dev/null +++ b/lib/libft/ft_isalnum.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 21:14:49 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:10:50 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' + && c <= '9')) + return (1); + return (0); +} diff --git a/lib/libft/ft_isalpha.c b/lib/libft/ft_isalpha.c new file mode 100644 index 0000000..054d96c --- /dev/null +++ b/lib/libft/ft_isalpha.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 19:59:23 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:10:10 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + return (1); + return (0); +} diff --git a/lib/libft/ft_isascii.c b/lib/libft/ft_isascii.c new file mode 100644 index 0000000..6570d44 --- /dev/null +++ b/lib/libft/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 21:23:25 by dkaiser #+# #+# */ +/* Updated: 2024/03/04 21:24:46 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + if (c >= 0 && c < 128) + return (1); + return (0); +} diff --git a/lib/libft/ft_isdigit.c b/lib/libft/ft_isdigit.c new file mode 100644 index 0000000..2601fee --- /dev/null +++ b/lib/libft/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 21:07:03 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:10:23 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isdigit(int c) +{ + if (c >= '0' && c <= '9') + return (1); + return (0); +} diff --git a/lib/libft/ft_isprint.c b/lib/libft/ft_isprint.c new file mode 100644 index 0000000..c04cf4f --- /dev/null +++ b/lib/libft/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 21:25:31 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:11:14 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int c) +{ + if (c >= ' ' && c <= '~') + return (1); + return (0); +} diff --git a/lib/libft/ft_itoa.c b/lib/libft/ft_itoa.c new file mode 100644 index 0000000..401ba6a --- /dev/null +++ b/lib/libft/ft_itoa.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 10:42:08 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:18:58 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int get_last_digit(int n) +{ + int last_digit; + + last_digit = n % 10; + if (last_digit < 0) + last_digit *= -1; + return (last_digit); +} + +static int get_len(int n) +{ + int len; + + len = 0; + if (n == 0) + return (1); + if (n < 0) + len++; + while (n) + { + len++; + n /= 10; + } + return (len); +} + +char *ft_itoa(int n) +{ + char *result; + int len; + + len = get_len(n); + result = malloc(sizeof(char) * (len + 1)); + if (!result) + return (0); + result[len] = '\0'; + if (n == 0) + result[0] = '0'; + if (n < 0) + result[0] = '-'; + while (n) + { + result[--len] = '0' + get_last_digit(n); + n /= 10; + } + return (result); +} + +/* #include <stdio.h> */ +/* int main() { */ +/* char* itoa = ft_itoa(0); */ +/* printf("%s\n", itoa); */ +/* } */ diff --git a/lib/libft/ft_lstadd_back_bonus.c b/lib/libft/ft_lstadd_back_bonus.c new file mode 100644 index 0000000..c4fb686 --- /dev/null +++ b/lib/libft/ft_lstadd_back_bonus.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 16:03:26 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 18:00:17 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *current; + + if (!*lst) + { + *lst = new; + return ; + } + current = *lst; + while (current->next) + { + current = current->next; + } + current->next = new; +} diff --git a/lib/libft/ft_lstadd_front_bonus.c b/lib/libft/ft_lstadd_front_bonus.c new file mode 100644 index 0000000..9c4c30e --- /dev/null +++ b/lib/libft/ft_lstadd_front_bonus.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 15:14:01 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 15:40:48 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **lst, t_list *new) +{ + new->next = *lst; + *lst = new; +} diff --git a/lib/libft/ft_lstclear_bonus.c b/lib/libft/ft_lstclear_bonus.c new file mode 100644 index 0000000..f661fc9 --- /dev/null +++ b/lib/libft/ft_lstclear_bonus.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 16:26:23 by dkaiser #+# #+# */ +/* Updated: 2024/03/11 12:48:24 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *current; + t_list *next; + + if (*lst) + { + current = *lst; + while (current->next) + { + next = current->next; + ft_lstdelone(current, del); + current = next; + } + ft_lstdelone(current, del); + } + *lst = NULL; +} diff --git a/lib/libft/ft_lstdelone_bonus.c b/lib/libft/ft_lstdelone_bonus.c new file mode 100644 index 0000000..9dd78c8 --- /dev/null +++ b/lib/libft/ft_lstdelone_bonus.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 16:20:31 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 16:36:18 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + del(lst->content); + free(lst); +} diff --git a/lib/libft/ft_lstiter_bonus.c b/lib/libft/ft_lstiter_bonus.c new file mode 100644 index 0000000..73efbe9 --- /dev/null +++ b/lib/libft/ft_lstiter_bonus.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 16:39:47 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 16:41:07 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + if (!lst) + return ; + while (lst->next) + { + f(lst->content); + lst = lst->next; + } + f(lst->content); +} diff --git a/lib/libft/ft_lstlast_bonus.c b/lib/libft/ft_lstlast_bonus.c new file mode 100644 index 0000000..e0b4d6d --- /dev/null +++ b/lib/libft/ft_lstlast_bonus.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 15:54:05 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 16:36:04 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + if (!lst) + return (0); + while (lst->next) + lst = lst->next; + return (lst); +} diff --git a/lib/libft/ft_lstmap_bonus.c b/lib/libft/ft_lstmap_bonus.c new file mode 100644 index 0000000..43120cd --- /dev/null +++ b/lib/libft/ft_lstmap_bonus.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 16:45:21 by dkaiser #+# #+# */ +/* Updated: 2024/03/11 13:36:23 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *result; + t_list *cur_new; + void *content; + + if (!lst || !f || !del) + return (NULL); + result = NULL; + while (lst) + { + content = f(lst->content); + cur_new = ft_lstnew(content); + if (!cur_new) + { + del(content); + ft_lstclear(&result, del); + return (NULL); + } + lst = lst->next; + ft_lstadd_back(&result, cur_new); + } + return (result); +} diff --git a/lib/libft/ft_lstnew_bonus.c b/lib/libft/ft_lstnew_bonus.c new file mode 100644 index 0000000..eeb6030 --- /dev/null +++ b/lib/libft/ft_lstnew_bonus.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 14:57:39 by dkaiser #+# #+# */ +/* Updated: 2024/03/11 12:52:00 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *result; + + result = malloc(sizeof(t_list)); + if (!result) + return (NULL); + result->content = content; + result->next = NULL; + return (result); +} + +/* #include <stdio.h> */ +/* int main() { */ +/* t_list l; */ +/* char s[] = "Hello"; */ + +/* l = *ft_lstnew(&s); */ +/* printf("%s\n", l.content); */ +/* } */ diff --git a/lib/libft/ft_lstsize_bonus.c b/lib/libft/ft_lstsize_bonus.c new file mode 100644 index 0000000..c91b0c9 --- /dev/null +++ b/lib/libft/ft_lstsize_bonus.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 15:35:38 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 16:36:09 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int len; + + if (!lst) + return (0); + len = 1; + while (lst->next) + { + lst = lst->next; + len++; + } + return (len); +} diff --git a/lib/libft/ft_memchr.c b/lib/libft/ft_memchr.c new file mode 100644 index 0000000..568faa6 --- /dev/null +++ b/lib/libft/ft_memchr.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 15:23:01 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:16:25 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#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 ((void *)s + i); + i++; + } + return (0); +} + +/* #include <stdio.h> */ +/* int main () { */ +/* char str[] = "Hello world"; */ +/* printf("memchr: %s\n", (char *) memchr(str, 'o', 11)); */ +/* printf("ft_memchr: %s\n", (char *) ft_memchr(str, 'o', 11)); */ +/* } */ diff --git a/lib/libft/ft_memcmp.c b/lib/libft/ft_memcmp.c new file mode 100644 index 0000000..0bd52df --- /dev/null +++ b/lib/libft/ft_memcmp.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 15:54:13 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:13:54 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + int result; + + i = 0; + result = 0; + while (!result && i < n) + { + result = *((unsigned char *)s1 + i) - *((unsigned char *)s2 + i); + i++; + } + return (result); +} + +/* #include <stdio.h> */ + +/* int main(void) */ +/* { */ +/* char str1[] = "Hello"; */ +/* char str2[] = "Hellu"; */ + +/* printf("memcmp: %d\n", memcmp(str1, str2, 5)); */ +/* printf("ft_memcmp: %d\n", ft_memcmp(str1, str2, 5)); */ +/* } */ diff --git a/lib/libft/ft_memcpy.c b/lib/libft/ft_memcpy.c new file mode 100644 index 0000000..768d500 --- /dev/null +++ b/lib/libft/ft_memcpy.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/05 11:15:12 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:14:24 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + char *dst_ptr; + char *src_ptr; + + dst_ptr = (char *)dst; + src_ptr = (char *)src; + if (!dst && !src) + return (dst); + while (n--) + *dst_ptr++ = *src_ptr++; + return (dst); +} + +/* #include <stdio.h> */ +/* int main(void) */ +/* { */ +/* char src[] = "a"; */ +/* char src2[] = "a"; */ +/* char dst[] = ""; */ +/* char dst2[] = ""; */ +/* printf("ft_memcpy: %s\n", (char *) ft_memcpy(dst, src, 20)); */ +/* printf("memcpy: %s\n", (char *) memcpy(dst2, src2, 20)); */ +/* } */ diff --git a/lib/libft/ft_memmove.c b/lib/libft/ft_memmove.c new file mode 100644 index 0000000..5d12f20 --- /dev/null +++ b/lib/libft/ft_memmove.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/05 11:41:44 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:14:38 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + size_t i; + + if (!dst && !src) + return (dst); + if (dst > src) + { + i = len; + while (i-- > 0) + { + *((char *)dst + i) = *((char *)src + i); + } + } + else + { + i = 0; + while (i < len) + { + *((char *)dst + i) = *((char *)src + i); + i++; + } + } + return (dst); +} + +/* #include <stdio.h> */ + +/* int main(void) */ +/* { */ +/* char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; */ +/* char text2[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; */ + +/* printf("memmove: %s\n", memmove(text + 5, text, 5)); */ +/* printf("ft_memmove: %s\n", ft_memmove(text2 + 5, text2, 5)); */ +/* } */ diff --git a/lib/libft/ft_memset.c b/lib/libft/ft_memset.c new file mode 100644 index 0000000..58c5e1e --- /dev/null +++ b/lib/libft/ft_memset.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/05 09:58:19 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:13:09 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *b, int c, size_t len) +{ + size_t i; + + i = 0; + while (i < len) + { + ((char *)b)[i] = (unsigned char)c; + i++; + } + return (b); +} + +/* #include <stdio.h> */ + +/* int main(void) */ +/* { */ +/* char str[] = "Hello world"; */ + +/* printf("STR: %s\n", str); */ +/* printf("ft_memset: %s\n", ft_memset((char *)str, 'A' + 255, 5)); */ +/* printf("memset: %s\n", memset((char *)str, 'A' + 255, 5)); */ +/* } */ diff --git a/lib/libft/ft_printaddr.c b/lib/libft/ft_printaddr.c new file mode 100644 index 0000000..f60ce0d --- /dev/null +++ b/lib/libft/ft_printaddr.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printaddr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/15 10:33:53 by dkaiser #+# #+# */ +/* Updated: 2024/03/18 11:42:58 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +static void printaddr_rec(unsigned long addr, int *len) +{ + char c; + int success; + + if (*len < 0) + return ; + if (addr % 16 < 10) + c = '0' + (addr % 16); + else + c = ('a' - 10) + (addr % 16); + if (addr > 15) + printaddr_rec(addr / 16, len); + success = write(1, &c, 1); + if (success < 0 || *len < 2) + *len = -1; + else + (*len)++; +} + +int ft_printaddr(void *addr) +{ + int len; + + len = write(1, "0x", 2); + printaddr_rec((unsigned long)addr, &len); + return (len); +} diff --git a/lib/libft/ft_printf.c b/lib/libft/ft_printf.c new file mode 100644 index 0000000..fc77f81 --- /dev/null +++ b/lib/libft/ft_printf.c @@ -0,0 +1,90 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/12 18:18:59 by dkaiser #+# #+# */ +/* Updated: 2024/03/18 11:42:34 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +static int print_char(char c) +{ + return (write(1, &c, 1)); +} + +static int print_str(char *str) +{ + int success; + int len; + + if (str) + { + len = 0; + while (str[len]) + len++; + success = write(1, str, len); + if (success < 0) + return (-1); + return (len); + } + else + { + success = write(1, "(null)", 6); + if (success == 6) + return (6); + return (-1); + } +} + +static int print_conv(va_list args, char c) +{ + if (c == 'c') + return (print_char(va_arg(args, int))); + if (c == 's') + return (print_str(va_arg(args, char *))); + if (c == 'p') + return (ft_printaddr(va_arg(args, void *))); + if (c == 'd' || c == 'i') + return (ft_printnbr(va_arg(args, int))); + if (c == 'u') + return (ft_printunbr(va_arg(args, unsigned int))); + if (c == 'x' || c == 'X') + return (ft_printhex(va_arg(args, unsigned int), c)); + if (c == '%') + return (print_char('%')); + return (-1); +} + +int ft_printf(const char *fmt, ...) +{ + int result; + int last_result; + int success; + va_list args; + + result = 0; + va_start(args, fmt); + while (*fmt) + { + last_result = result; + if (*fmt == '%') + result += print_conv(args, *(++fmt)); + else + { + success = write(1, fmt, 1); + if (success <= 0) + return (-1); + result++; + } + fmt++; + if (result < last_result) + return (-1); + } + va_end(args); + return (result); +} diff --git a/lib/libft/ft_printf.h b/lib/libft/ft_printf.h new file mode 100644 index 0000000..2378bfb --- /dev/null +++ b/lib/libft/ft_printf.h @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/12 18:19:47 by dkaiser #+# #+# */ +/* Updated: 2024/06/24 16:43:56 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_H +# define FT_PRINTF_H + +# include <stdarg.h> +# include <unistd.h> + +int ft_printf(const char *fmt, ...); +int ft_printnbr(int nbr); +int ft_printunbr(unsigned int nbr); +int ft_printhex(unsigned int nbr, char fmt); +int ft_printaddr(void *addr); +#endif // FT_PRINTF_H diff --git a/lib/libft/ft_printhex.c b/lib/libft/ft_printhex.c new file mode 100644 index 0000000..4605eac --- /dev/null +++ b/lib/libft/ft_printhex.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printhex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 15:50:35 by dkaiser #+# #+# */ +/* Updated: 2024/03/18 11:42:46 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +static void printhex_rec(unsigned int nbr, char fmt, int *len) +{ + char c; + int success; + + if (*len < 0) + return ; + if (nbr % 16 < 10) + c = '0' + (nbr % 16); + else + c = (fmt - 33) + (nbr % 16); + if (nbr > 15) + printhex_rec(nbr / 16, fmt, len); + if (*len < 0) + return ; + success = write(1, &c, 1); + if (success < 0) + *len = -1; + else + (*len)++; +} + +int ft_printhex(unsigned int nbr, char fmt) +{ + int len; + + len = 0; + printhex_rec(nbr, fmt, &len); + return (len); +} diff --git a/lib/libft/ft_printnbr.c b/lib/libft/ft_printnbr.c new file mode 100644 index 0000000..2a42ed8 --- /dev/null +++ b/lib/libft/ft_printnbr.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/13 15:18:40 by dkaiser #+# #+# */ +/* Updated: 2024/03/18 11:41:27 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +static void printnbr_rec(int n, int *len) +{ + char c; + int success; + + if (*len < 0) + return ; + c = '0' + n % 10; + if (n > 9) + printnbr_rec(n / 10, len); + if (*len < 0) + return ; + success = write(1, &c, 1); + if (success < 0) + *len = -1; + else + (*len)++; +} + +int ft_printnbr(int nbr) +{ + int len; + + len = 0; + if (nbr == -2147483648) + return (write(1, "-2147483648", 11)); + if (nbr < 0) + { + len = write(1, "-", 1); + nbr *= -1; + } + printnbr_rec(nbr, &len); + if (len < 0) + return (-1); + return (len); +} + +static void printunbr_rec(unsigned int n, int *len) +{ + char c; + int success; + + if (*len < 0) + return ; + c = '0' + n % 10; + if (n > 9) + printunbr_rec(n / 10, len); + if (*len < 0) + return ; + success = write(1, &c, 1); + if (success < 0) + *len = -1; + else + (*len)++; +} + +int ft_printunbr(unsigned int nbr) +{ + int len; + + len = 0; + printunbr_rec(nbr, &len); + if (len < 0) + return (-1); + return (len); +} diff --git a/lib/libft/ft_putchar_fd.c b/lib/libft/ft_putchar_fd.c new file mode 100644 index 0000000..5334e0e --- /dev/null +++ b/lib/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 20:36:14 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:19:59 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/lib/libft/ft_putendl_fd.c b/lib/libft/ft_putendl_fd.c new file mode 100644 index 0000000..f8de15e --- /dev/null +++ b/lib/libft/ft_putendl_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 20:47:17 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 14:07:58 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); + write(fd, "\n", 1); +} diff --git a/lib/libft/ft_putnbr_fd.c b/lib/libft/ft_putnbr_fd.c new file mode 100644 index 0000000..96f5f4b --- /dev/null +++ b/lib/libft/ft_putnbr_fd.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 10:43:09 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:20:59 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static void putnbr_fd_rec(int n, int fd) +{ + char c; + + c = '0' + n % 10; + if (n > 9) + putnbr_fd_rec(n / 10, fd); + write(fd, &c, 1); +} + +void ft_putnbr_fd(int n, int fd) +{ + if (n == -2147483648) + { + write(fd, "-2147483648", 11); + return ; + } + if (n < 0) + { + write(fd, "-", 1); + n *= -1; + } + putnbr_fd_rec(n, fd); +} diff --git a/lib/libft/ft_putstr_fd.c b/lib/libft/ft_putstr_fd.c new file mode 100644 index 0000000..cb78491 --- /dev/null +++ b/lib/libft/ft_putstr_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 20:43:05 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 14:07:37 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); +} diff --git a/lib/libft/ft_split.c b/lib/libft/ft_split.c new file mode 100644 index 0000000..fbd16c1 --- /dev/null +++ b/lib/libft/ft_split.c @@ -0,0 +1,114 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/08 15:36:44 by dkaiser #+# #+# */ +/* Updated: 2024/05/08 11:49:32 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int get_word_count(char const *s, char c) +{ + int word_count; + int cur_len; + + word_count = 0; + cur_len = 0; + while (*s) + { + if (!(*s) || *s == c) + { + cur_len = 0; + } + else + { + if (!cur_len) + word_count++; + cur_len++; + } + s++; + } + return (word_count); +} + +static char *get_next_token(char const **ptr_s, char c) +{ + int i; + int len; + char const *s; + char *result; + + s = *ptr_s; + while (*s && *s == c) + s++; + if (!*s) + return (0); + len = 0; + while (s[len] && s[len] != c) + len++; + result = malloc(sizeof(char) * (len + 1)); + if (!result) + return (0); + i = 0; + while (i < len) + result[i++] = *(s++); + result[i] = '\0'; + *ptr_s = s; + return (result); +} + +char **ft_split(char const *s, char c) +{ + char **result; + int word_count; + int w; + + word_count = get_word_count((char *)s, c); + result = malloc(sizeof(char *) * (word_count + 1)); + if (!result) + return (0); + w = 0; + while (w < word_count) + { + result[w] = get_next_token(&s, c); + if (!result[w]) + { + while (w--) + free(result[w]); + free(result); + return (0); + } + w++; + } + result[w] = 0; + return (result); +} + +void ft_free_split(char **split) +{ + int i; + + i = 0; + while (split[i]) + free(split[i++]); + free(split); +} + +/* #include <stdio.h> */ +/* int main() */ +/* { */ +/* char s[] = " split this for me !"; */ +/* char **split = ft_split(s, ' '); */ + +/* if (split) { */ +/* while(*split) { */ +/* printf("%s\n", *split); */ +/* split++; */ +/* } */ +/* } */ +/* } */ diff --git a/lib/libft/ft_strchr.c b/lib/libft/ft_strchr.c new file mode 100644 index 0000000..ecf522e --- /dev/null +++ b/lib/libft/ft_strchr.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 14:12:39 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:15:56 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *s, int c) +{ + int i; + + i = 0; + while (s[i] != '\0') + { + if (s[i] == (char)c) + return ((char *)&s[i]); + i++; + } + if (!(char)c) + return ((char *)&s[i]); + return (0); +} + +/* #include <stdio.h> */ +/* #include <string.h> */ + +/* int main(void) */ +/* { */ +/* char str[] = "teste"; */ + +/* printf("strchr: %p\n", strchr(str, '\0')); */ +/* printf("ft_strchr: %p\n", ft_strchr(str, '\0')); */ +/* } */ diff --git a/lib/libft/ft_strdup.c b/lib/libft/ft_strdup.c new file mode 100644 index 0000000..c7a6591 --- /dev/null +++ b/lib/libft/ft_strdup.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 19:54:16 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 15:28:58 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *s1) +{ + char *result; + int len; + + len = ft_strlen(s1); + result = malloc(len + 1); + if (!result) + return (0); + result[len] = '\0'; + while (len--) + result[len] = s1[len]; + return (result); +} + +/* #include <stdio.h> */ +/* int main() { */ +/* char *output; */ +/* char input[] = "test"; */ +/* output = ft_strdup(input); */ +/* printf("%s\n", output); */ +/* } */ diff --git a/lib/libft/ft_striteri.c b/lib/libft/ft_striteri.c new file mode 100644 index 0000000..e7c8b89 --- /dev/null +++ b/lib/libft/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 11:24:32 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:19:39 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + i = 0; + while (s[i]) + { + f(i, &s[i]); + i++; + } +} diff --git a/lib/libft/ft_strjoin.c b/lib/libft/ft_strjoin.c new file mode 100644 index 0000000..526592b --- /dev/null +++ b/lib/libft/ft_strjoin.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/07 10:15:33 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 14:02:07 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int copy_str(char *dst, const char *src) +{ + int i; + + i = 0; + while (src[i]) + { + dst[i] = src[i]; + i++; + } + return (i); +} + +char *ft_strjoin(char const *s1, char const *s2) +{ + int len; + char *result; + + len = ft_strlen(s1) + ft_strlen(s2); + result = malloc(len + 1); + if (result) + { + result[len] = '\0'; + len = copy_str(result, s1); + len = copy_str(result + len, s2); + return (result); + } + else + return (0); +} + +/* #include <stdio.h> */ + +/* int main(void) */ +/* { */ +/* char s1[] = "Hello "; */ +/* char s2[] = "World"; */ + +/* printf("%s\n", ft_strjoin(s1, s2)); */ +/* } */ diff --git a/lib/libft/ft_strlcat.c b/lib/libft/ft_strlcat.c new file mode 100644 index 0000000..d49dfad --- /dev/null +++ b/lib/libft/ft_strlcat.c @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 13:36:59 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:15:10 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* size_t ft_strlcat(char *dst, const char *src, size_t dstsize) */ +/* { */ +/* size_t len; */ +/* size_t i; */ + +/* if (dstsize == 0) */ +/* return (0); */ +/* len = 0; */ +/* while (len < dstsize - 1 && dst[len] != '\0') */ +/* { */ +/* len++; */ +/* } */ +/* i = 0; */ +/* while (len < dstsize - 1 && src[i] != '\0') */ +/* { */ +/* dst[len] = src[i]; */ +/* len++; */ +/* i++; */ +/* } */ +/* dst[len] = '\0'; */ +/* return (len); */ +/* } */ + +size_t ft_strlcat(char *dst, const char *src, size_t dstsize) +{ + size_t src_len; + size_t dst_len; + size_t i; + + src_len = 0; + while (src[src_len]) + src_len++; + dst_len = 0; + while (dst[dst_len]) + dst_len++; + if (dst_len >= dstsize) + return (dstsize + src_len); + i = 0; + while (i < src_len && dst_len + i < dstsize - 1) + { + dst[dst_len + i] = src[i]; + i++; + } + dst[dst_len + i] = '\0'; + return (dst_len + src_len); +} + +/* #include <stdio.h> */ +/* int main () { */ +/* char dst[12] = "Hello "; */ +/* char dst2[12] = "Hello "; */ +/* char src[] = "World123"; */ + +/* size_t len = strlcat(dst, src, 12); */ +/* size_t len2 = ft_strlcat(dst2, src, 12); */ +/* printf("strlcat (%zu): %s\n", len, dst); */ +/* printf("ft_strlcat (%zu): %s\n", len2, dst2); */ +/* } */ diff --git a/lib/libft/ft_strlcpy.c b/lib/libft/ft_strlcpy.c new file mode 100644 index 0000000..1cc62e5 --- /dev/null +++ b/lib/libft/ft_strlcpy.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 12:45:25 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:14:56 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dst, const char *src, size_t dstsize) +{ + size_t len; + + len = 0; + if (dstsize > 0) + { + while (len < dstsize - 1 && src[len] != '\0') + { + dst[len] = src[len]; + len++; + } + dst[len] = '\0'; + while (src[len] != '\0') + len++; + } + else + { + while (src[len] != '\0') + len++; + } + return (len); +} + +/* #include <stdio.h> */ + +/* int main(void) */ +/* { */ +/* char src[] = "Hello"; */ +/* char dst[] = "01234567890123456789"; */ +/* char dst2[] = "01234567890123456789"; */ +/* size_t len; */ +/* size_t len2; */ + +/* len = strlcpy(dst, src, 0); */ +/* len2 = ft_strlcpy(dst2, src, 0); */ +/* printf("strlcpy (%zu): %s\n", len, dst); */ +/* printf("ft_strlcpy (%zu): %s\n", len2, dst2); */ +/* } */ diff --git a/lib/libft/ft_strlen.c b/lib/libft/ft_strlen.c new file mode 100644 index 0000000..867c5eb --- /dev/null +++ b/lib/libft/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 21:29:35 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:11:48 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strlen(const char *str) +{ + int len; + + len = 0; + while (str[len]) + len++; + return (len); +} diff --git a/lib/libft/ft_strmapi.c b/lib/libft/ft_strmapi.c new file mode 100644 index 0000000..a500621 --- /dev/null +++ b/lib/libft/ft_strmapi.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 11:11:30 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 14:06:41 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + char *result; + unsigned int i; + + i = ft_strlen(s); + result = malloc(sizeof(char) * (i + 1)); + if (!result) + return (0); + result[i] = '\0'; + i = 0; + while (s[i]) + { + result[i] = f(i, s[i]); + i++; + } + return (result); +} + +/* char func (unsigned int i, char c) */ +/* { */ +/* c += i; */ +/* return (c); */ +/* } */ + +/* #include <stdio.h> */ +/* int main(){ */ +/* char str[] = "AAAAAAAA"; */ +/* printf("%s\n", ft_strmapi(str, func)); */ +/* } */ diff --git a/lib/libft/ft_strncmp.c b/lib/libft/ft_strncmp.c new file mode 100644 index 0000000..9d30ee7 --- /dev/null +++ b/lib/libft/ft_strncmp.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 14:45:10 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:16:10 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + int result; + + result = 0; + while (!result && n > 0 && (*s1 || *s2)) + { + result = (unsigned char)*s1 - (unsigned char)*s2; + if (*s1) + s1++; + if (*s2) + s2++; + n--; + } + return (result); +} + +/* #include <stdio.h> */ +/* int main() { */ +/* char str1[] = "Hello"; */ +/* char str2[] = "Hellu"; */ +/* printf("strncmp: %d\n", strncmp(str1, str2, 5)); */ +/* printf("ft_strncmp: %d\n", ft_strncmp(str1, str2, 5)); */ +/* } */ diff --git a/lib/libft/ft_strnstr.c b/lib/libft/ft_strnstr.c new file mode 100644 index 0000000..373e90c --- /dev/null +++ b/lib/libft/ft_strnstr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 16:07:54 by dkaiser #+# #+# */ +/* Updated: 2024/03/11 15:04:28 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *haystack, const char *needle, size_t len) +{ + size_t i; + size_t k; + + if (!*haystack && *needle) + return (0); + i = 0; + if (*needle == '\0' || needle == haystack) + return ((char *)haystack); + while (i < len && haystack[i]) + { + k = 0; + while (haystack[i + k] && haystack[i + k] == needle[k] && i + k < len) + k++; + if (!needle[k]) + return ((char *)haystack + i); + i++; + } + return (0); +} + +/* #include <stdio.h> */ + +/* int main(void) */ +/* { */ +/* char haystack[] = "abc"; */ +/* char needle[] = "abcde"; */ +/* size_t len = 5; */ + +/* printf("strnstr: %s\n", strnstr(haystack, needle, len)); */ +/* printf("ft_strnstr: %s\n", ft_strnstr(haystack, needle, len)); */ +/* } */ diff --git a/lib/libft/ft_strrchr.c b/lib/libft/ft_strrchr.c new file mode 100644 index 0000000..5d31654 --- /dev/null +++ b/lib/libft/ft_strrchr.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 14:25:30 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 12:51:38 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strrchr(const char *s, int c) +{ + int i; + char *last_occurrence; + + last_occurrence = 0; + i = 0; + while (s[i] != '\0') + { + if (s[i] == (char)c) + last_occurrence = (char *)&s[i]; + i++; + } + if (!(char)c) + last_occurrence = (char *)&s[i]; + return (last_occurrence); +} + +/* #include <stdio.h> */ +/* #include <string.h> */ + +/* int main(void) */ +/* { */ +/* char str[] = "Hello world"; */ + +/* printf("strrchr: %s\n", strrchr(str, 'o')); */ +/* printf("ft_strrchr: %s\n", ft_strrchr(str, 'o')); */ +/* } */ diff --git a/lib/libft/ft_strtrim.c b/lib/libft/ft_strtrim.c new file mode 100644 index 0000000..9caf12f --- /dev/null +++ b/lib/libft/ft_strtrim.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/07 10:24:17 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 14:03:13 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int is_in(char c, const char *str) +{ + while (*str) + { + if (c == *str) + return (1); + else + str++; + } + return (0); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + int i; + char *start; + char *end; + char *result; + + start = (char *)s1; + while (is_in(*start, set)) + start++; + i = ft_strlen(s1); + end = (char *)s1 + i - 1; + while (end > start && is_in(*end, set)) + end--; + i = end - start + 1; + result = malloc(i + 1); + if (result) + { + result[i] = '\0'; + i = 0; + while (start <= end) + result[i++] = *(start++); + return (result); + } + return (0); +} + +/* #include <stdio.h> */ + +/* int main(void) */ +/* { */ +/* char s1[] = " \t \t \t "; */ + +/* printf("%s\n", ft_strtrim(s1, " \t")); */ +/* } */ diff --git a/lib/libft/ft_substr.c b/lib/libft/ft_substr.c new file mode 100644 index 0000000..81ca8c6 --- /dev/null +++ b/lib/libft/ft_substr.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/06 21:58:31 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 15:39:38 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + unsigned int slen; + size_t i; + char *result; + + slen = ft_strlen(s); + if (start >= slen) + len = 0; + if (slen - start < len) + len = (slen - start); + result = malloc(len + 1); + if (!result) + return (0); + result[len] = '\0'; + i = 0; + while (i < len) + { + result[i] = s[i + start]; + i++; + } + return (result); +} + +/* #include <stdio.h> */ +/* int main () */ +/* { */ +/* char s[] = "Hello there"; */ +/* char *substr = ft_substr(s, 0, 2); */ +/* printf("%s\n", substr); */ +/* } */ diff --git a/lib/libft/ft_tolower.c b/lib/libft/ft_tolower.c new file mode 100644 index 0000000..c81b9ef --- /dev/null +++ b/lib/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 21:49:28 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:15:39 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + 32); + return (c); +} diff --git a/lib/libft/ft_toupper.c b/lib/libft/ft_toupper.c new file mode 100644 index 0000000..51e4ba6 --- /dev/null +++ b/lib/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/04 21:33:34 by dkaiser #+# #+# */ +/* Updated: 2024/03/10 13:15:26 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 32); + return (c); +} diff --git a/lib/libft/get_next_line.c b/lib/libft/get_next_line.c new file mode 100644 index 0000000..46edb73 --- /dev/null +++ b/lib/libft/get_next_line.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/15 14:13:51 by dkaiser #+# #+# */ +/* Updated: 2024/03/25 15:26:21 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" + +static int get_next_line_len(char *buf, int pos) +{ + int len; + + len = 0; + while (pos + len < BUFFER_SIZE) + { + if (buf[pos + len] == '\n') + { + len++; + break ; + } + if (!buf[pos + len]) + break ; + len++; + } + return (len); +} + +static void get_next_line_rec(int fd, char *buf, char **result, int pos) +{ + int len; + int i; + int readlen; + + len = get_next_line_len(buf, pos); + *result = str_add_buffer(*result, buf + pos, len); + if (pos + len == BUFFER_SIZE && buf[BUFFER_SIZE - 1] == '\n') + return (clear_buffer(buf, pos)); + i = 0; + while (i < len) + buf[pos + i++] = '\0'; + if (pos + len == BUFFER_SIZE && *result) + { + readlen = read(fd, buf, BUFFER_SIZE); + if (readlen < 0) + { + clear_buffer(buf, 0); + free(*result); + *result = NULL; + } + else if (readlen > 0) + get_next_line_rec(fd, buf, result, 0); + } +} + +char *get_next_line(int fd) +{ + static char buf[BUFFER_SIZE]; + int i; + char *result; + int readlen; + + i = 0; + readlen = 0; + result = NULL; + while (i < BUFFER_SIZE && !buf[i]) + i++; + if (i == BUFFER_SIZE) + { + readlen = read(fd, buf, BUFFER_SIZE); + if (readlen < 0) + clear_buffer(buf, 0); + else if (readlen > 0) + return (get_next_line(fd)); + return (NULL); + } + get_next_line_rec(fd, buf, &result, i); + return (result); +} diff --git a/lib/libft/get_next_line.h b/lib/libft/get_next_line.h new file mode 100644 index 0000000..5d3c6ee --- /dev/null +++ b/lib/libft/get_next_line.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/15 14:14:07 by dkaiser #+# #+# */ +/* Updated: 2024/06/24 16:44:01 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef GET_NEXT_LINE_H +# define GET_NEXT_LINE_H +# include <stdlib.h> +# include <unistd.h> + +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 42 +# endif + +int ft_strlen(const char *str); +char *get_next_line(int fd); +void clear_buffer(char *buf, int start); +char *str_add_buffer(char *old_str, char *buf, int buf_len); +#endif // GET_NEXT_LINE_H diff --git a/lib/libft/get_next_line_utils.c b/lib/libft/get_next_line_utils.c new file mode 100644 index 0000000..61171be --- /dev/null +++ b/lib/libft/get_next_line_utils.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/15 14:14:59 by dkaiser #+# #+# */ +/* Updated: 2024/03/26 10:49:08 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" + +int ft_strlen(const char *str) +{ + int len; + + if (!str) + return (0); + len = 0; + while (str[len]) + len++; + return (len); +} + +void clear_buffer(char *buf, int start) +{ + while (start < BUFFER_SIZE) + buf[start++] = '\0'; +} + +char *str_add_buffer(char *old_str, char *buf, int buf_len) +{ + char *result; + int len; + int i; + + if (!old_str) + len = buf_len; + else + len = ft_strlen(old_str) + buf_len; + result = malloc(sizeof(char) * (len + 1)); + if (!result) + { + free(old_str); + return (NULL); + } + result[len] = '\0'; + i = 0; + while (old_str && old_str[i]) + { + result[i] = old_str[i]; + i++; + } + while (i < len) + result[i++] = *(buf++); + free(old_str); + return (result); +} diff --git a/lib/libft/libft.h b/lib/libft/libft.h new file mode 100644 index 0000000..2de723b --- /dev/null +++ b/lib/libft/libft.h @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/10 16:37:54 by dkaiser #+# #+# */ +/* Updated: 2024/06/24 16:44:44 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include "ft_printf.h" +# include "get_next_line.h" +# include <stdarg.h> +# include <stdlib.h> +# include <string.h> +# include <unistd.h> + +int ft_isalpha(int c); +int ft_isdigit(int c); +int ft_isalnum(int c); +int ft_isprint(int c); +int ft_isascii(int c); +int ft_strlen(const char *str); +void *ft_memset(void *b, int c, size_t len); +void ft_bzero(void *s, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); +size_t ft_strlcat(char *dst, const char *src, size_t dstsize); +int ft_toupper(int c); +int ft_tolower(int c); +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +int ft_strncmp(const char *s1, const char *s2, size_t n); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +char *ft_strnstr(const char *haystack, const char *needle, + size_t len); +int ft_atoi(const char *str); +long ft_atol(const char *str); +void *ft_calloc(size_t count, size_t size); +char *ft_strdup(const char *s1); +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s1, char const *set); +char **ft_split(char const *s, char c); +void ft_free_split(char **split); +char *ft_itoa(int n); +char *ft_strmapi(char const *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 |
