diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b55e0c2 --- /dev/null +++ b/Makefile @@ -0,0 +1,91 @@ +CC = cc +CFLAGS = -Wall -Wextra -Werror +LDFLAGS = +AR = ar rcs +RM = /bin/rm -f + +NAME = libft.a +OBJDIR = . +SRCDIR = . +INCDIR = . + +unexport _SRC +_SRC += ft_atoi.c +_SRC += ft_bzero.c +_SRC += ft_calloc.c +_SRC += ft_isalnum.c +_SRC += ft_isalpha.c +_SRC += ft_isascii.c +_SRC += ft_isdigit.c +_SRC += ft_isprint.c +_SRC += ft_isspace.c +_SRC += ft_memchr.c +_SRC += ft_memcmp.c +_SRC += ft_memcpy.c +_SRC += ft_memmove.c +_SRC += ft_memset.c +_SRC += ft_strchr.c +_SRC += ft_strdup.c +_SRC += ft_strlcat.c +_SRC += ft_strlcpy.c +_SRC += ft_strlen.c +_SRC += ft_strncmp.c +_SRC += ft_strnstr.c +_SRC += ft_strrchr.c +_SRC += ft_tolower.c +_SRC += ft_toupper.c +# _SRC += ft_putchar_fd.c +# _SRC += ft_putendl_fd.c +# _SRC += ft_putnbr_fd.c +# _SRC += ft_putstr_fd.c + +# _SRC += ft_itoa.c +# _SRC += ft_strtrim.c +_SRC += ft_substr.c +# _SRC += ft_strjoin.c +# _SRC += ft_split.c +# _SRC += ft_striteri.c +# _SRC += ft_strmapi.c + +# _SRC += ft_lstadd_back.c +# _SRC += ft_lstadd_front.c +# _SRC += ft_lstclear +# _SRC += ft_lstdelone.c +# _SRC += ft_lstiter.c +# _SRC += ft_lstlast.c +# _SRC += ft_lstmap.c +# _SRC += ft_lstnew.c +# _SRC += ft_lstsize.c + +unexport _DEPS +_DEPS += libft.h + +_OBJ = $(_SRC:.c=.o) + +OBJ = $(addprefix $(OBJDIR)/,$(_OBJ)) +SRC = $(addprefix $(SRCDIR)/,$(_SRC)) +DEPS = $(addprefix $(INCDIR)/,$(_DEPS)) + +so: + $(CC) -nostartfiles -fPIC $(CFLAGS) $(SRC) + gcc -nostartfiles -shared -o libft.so $(OBJ) + +all: $(NAME) + +$(NAME): $(OBJ) + $(AR) $@ $^ + +$(OBJDIR)/%.o: %c $(DEPS) + $(CC) $(CFLAGS) -c -o $@ -I$(INCDIR) $< + +clean: + $(RM) $(OBJ) + +fclean: clean + $(RM) $(NAME) + +re: fclean all + +bonus: all + +.PHONY: re fclean clean all bonus diff --git a/a.out b/a.out new file mode 100755 index 0000000..5596abd Binary files /dev/null and b/a.out differ diff --git a/ft_atoi.c b/ft_atoi.c new file mode 100644 index 0000000..ea6e9a3 --- /dev/null +++ b/ft_atoi.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 17:28:18 by tosuman #+# #+# */ +/* Updated: 2023/05/22 17:28:18 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isspace(int c); +int ft_isdigit(int c); + +int ft_atoi(const char *nptr) +{ + int res; + int sign; + + while (ft_isspace(*nptr++)) + ; + sign = 1; + if (*--nptr == '+' || *nptr == '-') + if (*nptr++ == '-') + sign = -1; + res = 0; + while (ft_isdigit(*nptr)) + res = res * 10 + *nptr++ - '0'; + return (sign * res); +} diff --git a/ft_atoi.o b/ft_atoi.o new file mode 100644 index 0000000..a66baf1 Binary files /dev/null and b/ft_atoi.o differ diff --git a/ft_bzero.c b/ft_bzero.c new file mode 100644 index 0000000..6c1ed1a --- /dev/null +++ b/ft_bzero.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/11 11:55:27 by tosuman #+# #+# */ +/* Updated: 2023/05/11 11:55:28 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_bzero(void *s, size_t n) +{ + while (n--) + *(char *) s++ = (unsigned char) 0; +} diff --git a/ft_bzero.o b/ft_bzero.o new file mode 100644 index 0000000..748546e Binary files /dev/null and b/ft_bzero.o differ diff --git a/ft_calloc.c b/ft_calloc.c new file mode 100644 index 0000000..8f17e0f --- /dev/null +++ b/ft_calloc.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 17:39:55 by tosuman #+# #+# */ +/* Updated: 2023/05/22 17:39:56 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +void ft_bzero(void *s, size_t n); + +void *ft_calloc(size_t nmemb, size_t size) +{ + void *ret; + void *empty; + + if (nmemb * size == 0) + { + empty = malloc(0); + if (!empty) + return (0); + return (empty); + } + if (UINT_MAX / nmemb < size) + return (0); + ret = malloc(nmemb * size); + if (!ret) + return (0); + ft_bzero(ret, nmemb * size); + return (ret); +} diff --git a/ft_calloc.o b/ft_calloc.o new file mode 100644 index 0000000..91213ea Binary files /dev/null and b/ft_calloc.o differ diff --git a/ft_isalnum.o b/ft_isalnum.o new file mode 100644 index 0000000..e154d47 Binary files /dev/null and b/ft_isalnum.o differ diff --git a/ft_isalpha.o b/ft_isalpha.o new file mode 100644 index 0000000..dcf3c8c Binary files /dev/null and b/ft_isalpha.o differ diff --git a/ft_isascii.o b/ft_isascii.o new file mode 100644 index 0000000..0e03552 Binary files /dev/null and b/ft_isascii.o differ diff --git a/ft_isdigit.o b/ft_isdigit.o new file mode 100644 index 0000000..bfc0bfb Binary files /dev/null and b/ft_isdigit.o differ diff --git a/ft_isprint.o b/ft_isprint.o new file mode 100644 index 0000000..6a2f7b9 Binary files /dev/null and b/ft_isprint.o differ diff --git a/ft_isspace.c b/ft_isspace.c new file mode 100644 index 0000000..ae805a8 --- /dev/null +++ b/ft_isspace.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isspace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 17:38:55 by tosuman #+# #+# */ +/* Updated: 2023/05/22 17:39:02 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isspace(int c) +{ + return (c == ' ' + || c == '\n' + || c == '\r' + || c == '\t' + || c == '\f' + || c == '\v'); +} diff --git a/ft_isspace.o b/ft_isspace.o new file mode 100644 index 0000000..e96eb9c Binary files /dev/null and b/ft_isspace.o differ diff --git a/ft_itoa.c b/ft_itoa.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstadd_back.c b/ft_lstadd_back.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstadd_front.c b/ft_lstadd_front.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstclear b/ft_lstclear new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstdelone.c b/ft_lstdelone.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstiter.c b/ft_lstiter.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstlast.c b/ft_lstlast.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstmap.c b/ft_lstmap.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstnew.c b/ft_lstnew.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_lstsize.c b/ft_lstsize.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_memchr.c b/ft_memchr.c new file mode 100644 index 0000000..2689fc9 --- /dev/null +++ b/ft_memchr.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 16:34:06 by tosuman #+# #+# */ +/* Updated: 2023/05/22 16:34:06 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void *ft_memchr(const void *s, int c, size_t n) +{ + unsigned char *us; + + us = (unsigned char *) s; + while (n--) + if (*us++ == (unsigned char) c) + return (--us); + return (0); +} diff --git a/ft_memchr.o b/ft_memchr.o new file mode 100644 index 0000000..a940e2c Binary files /dev/null and b/ft_memchr.o differ diff --git a/ft_memcmp.c b/ft_memcmp.c new file mode 100644 index 0000000..9c5bd86 --- /dev/null +++ b/ft_memcmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 16:44:15 by tosuman #+# #+# */ +/* Updated: 2023/05/22 16:44:15 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned char *us1; + unsigned char *us2; + + us1 = (unsigned char *) s1; + us2 = (unsigned char *) s2; + if (!n) + return (0); + while (n--) + if (*us1++ != *us2++) + return (*--us1 - *--us2); + return (0); +} diff --git a/ft_memcmp.o b/ft_memcmp.o new file mode 100644 index 0000000..0b59749 Binary files /dev/null and b/ft_memcmp.o differ diff --git a/ft_memcpy.c b/ft_memcpy.c new file mode 100644 index 0000000..b1e1f66 --- /dev/null +++ b/ft_memcpy.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/11 13:28:20 by tosuman #+# #+# */ +/* Updated: 2023/05/11 13:28:21 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + char *d; + const char *s; + + if (!src && !dest) + return (0); + d = dest; + s = src; + while (n--) + *d++ = *s++; + return (dest); +} diff --git a/ft_memcpy.o b/ft_memcpy.o new file mode 100644 index 0000000..39fc966 Binary files /dev/null and b/ft_memcpy.o differ diff --git a/ft_memmove.c b/ft_memmove.c new file mode 100644 index 0000000..372c400 --- /dev/null +++ b/ft_memmove.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/11 16:19:10 by tosuman #+# #+# */ +/* Updated: 2023/05/11 16:19:11 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + char *d; + const char *s; + + if (!src && !dest) + return (0); + d = dest; + s = src; + if (src >= dest) + while (n--) + *d++ = *s++; + else + while (n--) + *(d + n) = *(s + n); + return (dest); +} diff --git a/ft_memmove.o b/ft_memmove.o new file mode 100644 index 0000000..99a0ff5 Binary files /dev/null and b/ft_memmove.o differ diff --git a/ft_memset.c b/ft_memset.c new file mode 100644 index 0000000..f07fa9f --- /dev/null +++ b/ft_memset.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/11 10:06:42 by tosuman #+# #+# */ +/* Updated: 2023/05/11 10:06:42 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void *ft_memset(void *s, int c, unsigned long n) +{ + unsigned char *ptr; + + ptr = (unsigned char *) s; + while (n-- > 0) + *ptr++ = c; + return (s); +} diff --git a/ft_memset.o b/ft_memset.o new file mode 100644 index 0000000..57bee77 Binary files /dev/null and b/ft_memset.o differ diff --git a/ft_putchar_fd.c b/ft_putchar_fd.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_putendl_fd.c b/ft_putendl_fd.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_putnbr_fd.c b/ft_putnbr_fd.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_putstr_fd.c b/ft_putstr_fd.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_split.c b/ft_split.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_strchr.c b/ft_strchr.c new file mode 100644 index 0000000..13aec53 --- /dev/null +++ b/ft_strchr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 16:20:31 by tosuman #+# #+# */ +/* Updated: 2023/05/22 16:20:33 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strchr(const char *s, int c) +{ + while (*s) + if (*s++ == (unsigned char) c) + return ((char *)--s); + if (*s == (unsigned char) c) + return ((char *) s); + else + return (0); +} diff --git a/ft_strchr.o b/ft_strchr.o new file mode 100644 index 0000000..3c234fc Binary files /dev/null and b/ft_strchr.o differ diff --git a/ft_strdup.c b/ft_strdup.c new file mode 100644 index 0000000..67f05db --- /dev/null +++ b/ft_strdup.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 19:12:24 by tosuman #+# #+# */ +/* Updated: 2023/05/22 19:15:06 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +size_t ft_strlen(const char *s); +size_t ft_strlcpy(char *dst, const char *src, size_t size); + +char *ft_strdup(const char *s) +{ + char *s2; + size_t len; + + len = ft_strlen(s); + s2 = malloc(sizeof(char) * (len + 1)); + if (!s2) + return (0); + ft_strlcpy(s2, (char *) s, len + 1); + return (s2); +} diff --git a/ft_strdup.o b/ft_strdup.o new file mode 100644 index 0000000..eaca3d6 Binary files /dev/null and b/ft_strdup.o differ diff --git a/ft_striteri.c b/ft_striteri.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_strjoin.c b/ft_strjoin.c new file mode 100644 index 0000000..973af94 --- /dev/null +++ b/ft_strjoin.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/24 13:43:29 by tosuman #+# #+# */ +/* Updated: 2023/05/24 13:43:30 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const s2) +{ + size_t total_len; + char *joined_str; + + total_len = ft_strlen(s1) + ft_strlen(s2); + joined_str = ft_calloc(sizeof(char) * (total_len + 1)); + if (!joined_str) + return (0); + ft_strlcpy(joined_str, s1, total_len); + ft_strlcat(joined_str, s2, total_len); + return (joined_str); +} diff --git a/ft_strlcat.c b/ft_strlcat.c new file mode 100644 index 0000000..5be81cc --- /dev/null +++ b/ft_strlcat.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */ +/* Updated: 2023/05/11 16:55:01 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +size_t ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t idx; + size_t slen; + size_t dlen; + + idx = 0; + while (dst[idx]) + ++idx; + dlen = idx; + if (dlen > size) + return (size); + slen = 0; + while (src[slen]) + dst[idx++] = src[slen++]; + return (dlen + slen); +} + +// #include +// #include +// int main() +// { +// printf("%d", ft_strlcat()); +// printf("%d", ft_strlcat()); +// return (0); +// } + +/* +Alternative implementation +size_t ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t dst_len; + size_t src_len; + + if ((!dst || !src) && size == 0) + return (0); + dst_len = 0; + src_len = -1; + while (*dst++) + ++dst_len; + while (src[++src_len]) + ; + if (size <= dst_len) + return (size + src_len); + if (--dst && dst_len > size) + return (size + dst_len); + while (src_len-- && ++dst_len < size) + *dst++ = *src++; + if (dst_len-- == size) + --dst_len; + *dst = 0; + return (dst_len + src_len); +} +*/ diff --git a/ft_strlcat.o b/ft_strlcat.o new file mode 100644 index 0000000..674ebad Binary files /dev/null and b/ft_strlcat.o differ diff --git a/ft_strlcpy.c b/ft_strlcpy.c new file mode 100644 index 0000000..693e972 --- /dev/null +++ b/ft_strlcpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */ +/* Updated: 2023/05/11 16:55:01 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +size_t ft_strlcpy(char *dst, const char *src, size_t size) +{ + char *d; + size_t len; + + d = dst; + len = 0; + while (++len < size && *src) + *d++ = *src++; + if (size) + *d = 0; + while (*src && src++) + len++; + return (len - 1); +} diff --git a/ft_strlcpy.o b/ft_strlcpy.o new file mode 100644 index 0000000..9d6feab Binary files /dev/null and b/ft_strlcpy.o differ diff --git a/ft_strlen.o b/ft_strlen.o new file mode 100644 index 0000000..839e175 Binary files /dev/null and b/ft_strlen.o differ diff --git a/ft_strmapi.c b/ft_strmapi.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_strncmp.c b/ft_strncmp.c new file mode 100644 index 0000000..ecdcfea --- /dev/null +++ b/ft_strncmp.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 16:29:43 by tosuman #+# #+# */ +/* Updated: 2023/05/22 16:29:44 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + unsigned char *us1; + unsigned char *us2; + + if (!n) + return (0); + us1 = (unsigned char *) s1; + us2 = (unsigned char *) s2; + while (*us1 && *us2 && *us1 == *us2 && --n) + { + us1++; + us2++; + } + if (*us1 != *us2) + return ((*us1 - *us2 != 0) + * (-2 * (*us1 - *us2 < 0) + 1)); + return (0); +} diff --git a/ft_strncmp.o b/ft_strncmp.o new file mode 100644 index 0000000..7f8c6a7 Binary files /dev/null and b/ft_strncmp.o differ diff --git a/ft_strnstr.c b/ft_strnstr.c new file mode 100644 index 0000000..4d3b540 --- /dev/null +++ b/ft_strnstr.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 17:05:27 by tosuman #+# #+# */ +/* Updated: 2023/05/22 17:05:28 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +size_t ft_strlen(const char *s); +int ft_memcmp(const void *s1, const void *s2, size_t n); + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t l_len; + size_t b_len; + + if ((!big || !little) && len == 0) + return (0); + b_len = ft_strlen(big); + l_len = ft_strlen(little); + if (b_len < l_len || len < l_len) + return (0); + if (b_len - l_len + 1 < len) + len = b_len - l_len + 1; + else if (len >= l_len) + len = len - l_len; + len += !len; + while (len--) + if (!ft_memcmp(big++, little, l_len)) + return ((char *)--big); + return (0); +} diff --git a/ft_strnstr.o b/ft_strnstr.o new file mode 100644 index 0000000..3c5aa4a Binary files /dev/null and b/ft_strnstr.o differ diff --git a/ft_strrchr.c b/ft_strrchr.c new file mode 100644 index 0000000..836b795 --- /dev/null +++ b/ft_strrchr.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 16:24:42 by tosuman #+# #+# */ +/* Updated: 2023/05/22 16:24:42 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strrchr(const char *s, int c) +{ + char *last; + + last = 0; + while (*s) + if (*s++ == (char) c) + last = (char *)(s - 1); + if (*s == (char) c) + return ((char *) s); + return (last); +} diff --git a/ft_strrchr.o b/ft_strrchr.o new file mode 100644 index 0000000..b903928 Binary files /dev/null and b/ft_strrchr.o differ diff --git a/ft_strtrim.c b/ft_strtrim.c new file mode 100644 index 0000000..e69de29 diff --git a/ft_substr.c b/ft_substr.c new file mode 100644 index 0000000..52339e5 --- /dev/null +++ b/ft_substr.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/24 13:23:00 by tosuman #+# #+# */ +/* Updated: 2023/05/24 13:23:01 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void *ft_calloc(size_t nmemb, size_t size); +size_t ft_strlcpy(char *dst, const char *src, size_t size); + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + unsigned int idx; + size_t real_len; + char *substr; + char *empty; + + idx = -1; + while (s[++idx] && idx < start) + ; + if (!s[idx]) + { + empty = ft_calloc(1, sizeof(char)); + if (!empty) + return (0); + return (empty); + } + real_len = 0; + while (++real_len <= len && s[idx + real_len - 1]) + ; + substr = malloc(sizeof(char) * real_len); + if (!substr) + return (0); + ft_strlcpy(substr, s + idx, real_len); + return (substr); +} diff --git a/ft_substr.o b/ft_substr.o new file mode 100644 index 0000000..2801b67 Binary files /dev/null and b/ft_substr.o differ diff --git a/ft_tolower.c b/ft_tolower.c new file mode 100644 index 0000000..f4039ae --- /dev/null +++ b/ft_tolower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/16 14:37:20 by tosuman #+# #+# */ +/* Updated: 2023/05/16 14:37:40 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c + 32); + return (c); +} diff --git a/ft_tolower.o b/ft_tolower.o new file mode 100644 index 0000000..560b038 Binary files /dev/null and b/ft_tolower.o differ diff --git a/ft_toupper.c b/ft_toupper.c new file mode 100644 index 0000000..69b0936 --- /dev/null +++ b/ft_toupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/22 16:12:47 by tosuman #+# #+# */ +/* Updated: 2023/05/22 16:12:47 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c - 32); + return (c); +} diff --git a/ft_toupper.o b/ft_toupper.o new file mode 100644 index 0000000..7bd3b7e Binary files /dev/null and b/ft_toupper.o differ diff --git a/libft.a b/libft.a new file mode 100644 index 0000000..d78df99 Binary files /dev/null and b/libft.a differ diff --git a/libft.h b/libft.h new file mode 100644 index 0000000..41676aa --- /dev/null +++ b/libft.h @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tosuman +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/05/11 11:31:44 by tosuman #+# #+# */ +/* Updated: 2023/05/11 11:31:46 by tosuman ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include + +int ft_atoi(const char *nptr); +void ft_bzero(void *s, size_t n); +void *ft_calloc(size_t nmemb, size_t size); +int ft_isalnum(int c); +int ft_isalpha(int c); +int ft_isascii(int c); +int ft_isdigit(int c); +int ft_isprint(int c); +int ft_isspace(int c); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +void *ft_memcpy(void *dest, const void *src, size_t n); +void *ft_memmove(void *dest, const void *src, size_t n); +void *ft_memset(void *s, int c, size_t n); +char *ft_strchr(const char *s, int c); +char *ft_strdup(const char *s); +size_t ft_strlcat(char *dst, const char *src, size_t size); +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlen(const char *s); +int ft_strncmp(const char *s1, const char *s2, size_t n); +char *ft_strnstr(const char *big, const char *little, size_t len); +char *ft_strrchr(const char *s, int c); +int ft_tolower(int c); +int ft_toupper(int c); +char *ft_substr(char const *s, unsigned int start, size_t len); + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +#endif diff --git a/libft.so b/libft.so new file mode 100755 index 0000000..1384d14 Binary files /dev/null and b/libft.so differ