From: Dominik Kaiser Date: Wed, 8 May 2024 11:14:19 +0000 (+0200) Subject: Add libft as dir X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=42%2Fpipex.git Add libft as dir --- diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..bb4d8c1 --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,76 @@ +NAME=libft.a +CC=cc +CFLAGS=-Wall -Wextra -Werror + +SRC_FILES = 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_FILES = $(SRC_FILES:.c=.o) + +all: $(NAME) + @: + +$(NAME): $(OBJ_FILES) + @ar rcs $(NAME) $(OBJ_FILES) + @echo "[$(NAME)] Created archive." + +%.o:%.c + @$(CC) $(CFLAGS) -c -o $@ $< + @echo "[$(NAME)] Compiled $<." + +clean: + @$(foreach file, $(OBJ_FILES), test -f $(file) && rm $(file) && echo "[$(NAME)] Removed $(file)." || :;) +fclean: clean + @test -f $(NAME) && rm -f $(NAME) && echo "[$(NAME)] Removed archive." || : + +re: fclean all + +.PHONY: all clean fclean re diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100644 index 0000000..90200fb --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = '\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 */ +/* #include */ +/* int main() { */ +/* char str[] = " -42eaeouai"; */ +/* printf("atoi: %d\n", atoi(str)); */ +/* printf("ft_atoi: %d\n", ft_atoi(str)); */ +/* } */ diff --git a/libft/ft_atol.c b/libft/ft_atol.c new file mode 100644 index 0000000..ae47db0 --- /dev/null +++ b/libft/ft_atol.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atol.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = '\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/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100644 index 0000000..78af51a --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' + && c <= '9')) + return (1); + return (0); +} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100644 index 0000000..054d96c --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + return (1); + return (0); +} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100644 index 0000000..6570d44 --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = 0 && c < 128) + return (1); + return (0); +} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100644 index 0000000..2601fee --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = '0' && c <= '9') + return (1); + return (0); +} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100644 index 0000000..c04cf4f --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = ' ' && c <= '~') + return (1); + return (0); +} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100644 index 0000000..401ba6a --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* int main() { */ +/* char* itoa = ft_itoa(0); */ +/* printf("%s\n", itoa); */ +/* } */ diff --git a/libft/ft_lstadd_back_bonus.c b/libft/ft_lstadd_back_bonus.c new file mode 100644 index 0000000..c4fb686 --- /dev/null +++ b/libft/ft_lstadd_back_bonus.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next) + { + current = current->next; + } + current->next = new; +} diff --git a/libft/ft_lstadd_front_bonus.c b/libft/ft_lstadd_front_bonus.c new file mode 100644 index 0000000..9c4c30e --- /dev/null +++ b/libft/ft_lstadd_front_bonus.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next = *lst; + *lst = new; +} diff --git a/libft/ft_lstclear_bonus.c b/libft/ft_lstclear_bonus.c new file mode 100644 index 0000000..f661fc9 --- /dev/null +++ b/libft/ft_lstclear_bonus.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next) + { + next = current->next; + ft_lstdelone(current, del); + current = next; + } + ft_lstdelone(current, del); + } + *lst = NULL; +} diff --git a/libft/ft_lstdelone_bonus.c b/libft/ft_lstdelone_bonus.c new file mode 100644 index 0000000..9dd78c8 --- /dev/null +++ b/libft/ft_lstdelone_bonus.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser content); + free(lst); +} diff --git a/libft/ft_lstiter_bonus.c b/libft/ft_lstiter_bonus.c new file mode 100644 index 0000000..73efbe9 --- /dev/null +++ b/libft/ft_lstiter_bonus.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next) + { + f(lst->content); + lst = lst->next; + } + f(lst->content); +} diff --git a/libft/ft_lstlast_bonus.c b/libft/ft_lstlast_bonus.c new file mode 100644 index 0000000..e0b4d6d --- /dev/null +++ b/libft/ft_lstlast_bonus.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next) + lst = lst->next; + return (lst); +} diff --git a/libft/ft_lstmap_bonus.c b/libft/ft_lstmap_bonus.c new file mode 100644 index 0000000..43120cd --- /dev/null +++ b/libft/ft_lstmap_bonus.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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/libft/ft_lstnew_bonus.c b/libft/ft_lstnew_bonus.c new file mode 100644 index 0000000..eeb6030 --- /dev/null +++ b/libft/ft_lstnew_bonus.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser content = content; + result->next = NULL; + return (result); +} + +/* #include */ +/* int main() { */ +/* t_list l; */ +/* char s[] = "Hello"; */ + +/* l = *ft_lstnew(&s); */ +/* printf("%s\n", l.content); */ +/* } */ diff --git a/libft/ft_lstsize_bonus.c b/libft/ft_lstsize_bonus.c new file mode 100644 index 0000000..c91b0c9 --- /dev/null +++ b/libft/ft_lstsize_bonus.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next) + { + lst = lst->next; + len++; + } + return (len); +} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100644 index 0000000..568faa6 --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* 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/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100644 index 0000000..0bd52df --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ + +/* 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/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100644 index 0000000..768d500 --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* 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/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100644 index 0000000..5d12f20 --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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 */ + +/* 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/libft/ft_memset.c b/libft/ft_memset.c new file mode 100644 index 0000000..58c5e1e --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ + +/* 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/libft/ft_printaddr.c b/libft/ft_printaddr.c new file mode 100644 index 0000000..f60ce0d --- /dev/null +++ b/libft/ft_printaddr.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printaddr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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/libft/ft_printf.c b/libft/ft_printf.c new file mode 100644 index 0000000..fc77f81 --- /dev/null +++ b/libft/ft_printf.c @@ -0,0 +1,90 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser +# include + +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/libft/ft_printhex.c b/libft/ft_printhex.c new file mode 100644 index 0000000..4605eac --- /dev/null +++ b/libft/ft_printhex.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printhex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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/libft/ft_printnbr.c b/libft/ft_printnbr.c new file mode 100644 index 0000000..2a42ed8 --- /dev/null +++ b/libft/ft_printnbr.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100644 index 0000000..5334e0e --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100644 index 0000000..cb78491 --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* 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/libft/ft_strchr.c b/libft/ft_strchr.c new file mode 100644 index 0000000..ecf522e --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* #include */ + +/* 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/libft/ft_strdup.c b/libft/ft_strdup.c new file mode 100644 index 0000000..c7a6591 --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* int main() { */ +/* char *output; */ +/* char input[] = "test"; */ +/* output = ft_strdup(input); */ +/* printf("%s\n", output); */ +/* } */ diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c new file mode 100644 index 0000000..e7c8b89 --- /dev/null +++ b/libft/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ + +/* int main(void) */ +/* { */ +/* char s1[] = "Hello "; */ +/* char s2[] = "World"; */ + +/* printf("%s\n", ft_strjoin(s1, s2)); */ +/* } */ diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100644 index 0000000..d49dfad --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = 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 */ +/* 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/libft/ft_strlcpy.c b/libft/ft_strlcpy.c new file mode 100644 index 0000000..1cc62e5 --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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 */ + +/* 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/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100644 index 0000000..867c5eb --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* int main(){ */ +/* char str[] = "AAAAAAAA"; */ +/* printf("%s\n", ft_strmapi(str, func)); */ +/* } */ diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c new file mode 100644 index 0000000..9d30ee7 --- /dev/null +++ b/libft/ft_strncmp.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 0 && (*s1 || *s2)) + { + result = (unsigned char)*s1 - (unsigned char)*s2; + if (*s1) + s1++; + if (*s2) + s2++; + n--; + } + return (result); +} + +/* #include */ +/* 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/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100644 index 0000000..373e90c --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ + +/* 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/libft/ft_strrchr.c b/libft/ft_strrchr.c new file mode 100644 index 0000000..5d31654 --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* #include */ + +/* 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/libft/ft_strtrim.c b/libft/ft_strtrim.c new file mode 100644 index 0000000..9caf12f --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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 */ + +/* int main(void) */ +/* { */ +/* char s1[] = " \t \t \t "; */ + +/* printf("%s\n", ft_strtrim(s1, " \t")); */ +/* } */ diff --git a/libft/ft_substr.c b/libft/ft_substr.c new file mode 100644 index 0000000..81ca8c6 --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = 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 */ +/* int main () */ +/* { */ +/* char s[] = "Hello there"; */ +/* char *substr = ft_substr(s, 0, 2); */ +/* printf("%s\n", substr); */ +/* } */ diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100644 index 0000000..c81b9ef --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = 'A' && c <= 'Z') + return (c + 32); + return (c); +} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c new file mode 100644 index 0000000..51e4ba6 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser = 'a' && c <= 'z') + return (c - 32); + return (c); +} diff --git a/libft/get_next_line.c b/libft/get_next_line.c new file mode 100644 index 0000000..46edb73 --- /dev/null +++ b/libft/get_next_line.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 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/libft/get_next_line.h b/libft/get_next_line.h new file mode 100644 index 0000000..63c477b --- /dev/null +++ b/libft/get_next_line.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser +# include + +# 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/libft/get_next_line_utils.c b/libft/get_next_line_utils.c new file mode 100644 index 0000000..61171be --- /dev/null +++ b/libft/get_next_line_utils.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser +# include +# include + +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