Compare commits
2 Commits
91730ee04c
...
01b559a96f
Author | SHA1 | Date |
---|---|---|
|
01b559a96f | |
|
d21e3a9025 |
37
Makefile
37
Makefile
|
@ -33,31 +33,32 @@ _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_putchar_fd.c
|
||||
_SRC += ft_putendl_fd.c
|
||||
_SRC += ft_putnbr_fd.c
|
||||
_SRC += ft_putstr_fd.c
|
||||
|
||||
# _SRC += ft_itoa.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_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
|
||||
_SRC += ft_lstnew.c
|
||||
_SRC += ft_lstadd_front.c
|
||||
_SRC += ft_lstsize.c
|
||||
_SRC += ft_lstlast.c
|
||||
_SRC += ft_lstadd_back.c
|
||||
_SRC += ft_lstclear.c
|
||||
_SRC += ft_lstdelone.c
|
||||
_SRC += ft_lstiter.c
|
||||
_SRC += ft_lstmap.c
|
||||
|
||||
_SRC += ft_char_in_charset.c
|
||||
_SRC += ft_isspace.c
|
||||
_SRC += ft_abs.c
|
||||
|
||||
unexport _DEPS
|
||||
_DEPS += libft.h
|
||||
|
@ -68,10 +69,6 @@ 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)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_abs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/03 11:52:45 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/03 11:52:45 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
unsigned int ft_abs(int n)
|
||||
{
|
||||
if (n > 0)
|
||||
return (n);
|
||||
else
|
||||
return (-(unsigned int) n);
|
||||
}
|
BIN
ft_bzero.o
BIN
ft_bzero.o
Binary file not shown.
BIN
ft_calloc.o
BIN
ft_calloc.o
Binary file not shown.
BIN
ft_isalnum.o
BIN
ft_isalnum.o
Binary file not shown.
BIN
ft_isalpha.o
BIN
ft_isalpha.o
Binary file not shown.
BIN
ft_isascii.o
BIN
ft_isascii.o
Binary file not shown.
BIN
ft_isdigit.o
BIN
ft_isdigit.o
Binary file not shown.
BIN
ft_isprint.o
BIN
ft_isprint.o
Binary file not shown.
BIN
ft_isspace.o
BIN
ft_isspace.o
Binary file not shown.
43
ft_itoa.c
43
ft_itoa.c
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/03 11:32:41 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/03 11:32:41 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *str;
|
||||
size_t n_len;
|
||||
unsigned int n_cpy;
|
||||
int is_neg;
|
||||
|
||||
is_neg = n < 0;
|
||||
n_len = 0;
|
||||
n_cpy = ft_abs(n) + !n;
|
||||
while (n_cpy * ++n_len != 0)
|
||||
n_cpy /= 10;
|
||||
--n_len;
|
||||
str = malloc(sizeof(*str) * (n_len + is_neg + 1));
|
||||
if (!str)
|
||||
return (0);
|
||||
str += n_len + is_neg;
|
||||
n_cpy = ft_abs(n);
|
||||
*str-- = 0;
|
||||
while (n_len--)
|
||||
{
|
||||
*str-- = n_cpy % 10 + '0';
|
||||
n_cpy /= 10;
|
||||
}
|
||||
if (is_neg)
|
||||
*str-- = '-';
|
||||
return (++str);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/24 16:29:20 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 16:38:53 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *last;
|
||||
|
||||
if (!lst)
|
||||
return ;
|
||||
if (!*lst)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
last = ft_lstlast(*lst);
|
||||
last->next = new;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/14 11:57:15 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 16:38:36 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (!lst)
|
||||
return ;
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/24 16:47:41 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 17:06:04 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
tmp = *lst;
|
||||
while (tmp)
|
||||
{
|
||||
*lst = tmp->next;
|
||||
ft_lstdelone(tmp, del);
|
||||
tmp = *lst;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/24 16:44:13 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 16:45:34 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
22
ft_lstiter.c
22
ft_lstiter.c
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/24 16:57:28 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 17:26:38 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
(*f)(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
22
ft_lstlast.c
22
ft_lstlast.c
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/24 16:26:09 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 16:28:25 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (!lst)
|
||||
return (lst);
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
42
ft_lstmap.c
42
ft_lstmap.c
|
@ -0,0 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/24 17:10:04 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/26 20:32:34 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *new_lst;
|
||||
t_list *new_elem;
|
||||
|
||||
if (!lst || !f)
|
||||
return (0);
|
||||
new_lst = (void *)0;
|
||||
while (lst)
|
||||
{
|
||||
new_elem = ft_lstnew(f(lst->content));
|
||||
if (!new_elem)
|
||||
{
|
||||
while (new_lst)
|
||||
{
|
||||
new_elem = new_lst->next;
|
||||
del(new_lst->content);
|
||||
free(new_lst);
|
||||
new_lst = new_elem;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
ft_lstadd_back(&new_lst, new_elem);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (new_lst);
|
||||
}
|
27
ft_lstnew.c
27
ft_lstnew.c
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:55:31 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 17:36:37 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = malloc(sizeof(*new));
|
||||
if (!new)
|
||||
return (0);
|
||||
new->content = content;
|
||||
new->next = (void *)0;
|
||||
return (new);
|
||||
}
|
26
ft_lstsize.c
26
ft_lstsize.c
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/24 15:46:41 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/24 16:25:28 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (lst)
|
||||
{
|
||||
lst = lst -> next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
BIN
ft_memchr.o
BIN
ft_memchr.o
Binary file not shown.
BIN
ft_memcmp.o
BIN
ft_memcmp.o
Binary file not shown.
BIN
ft_memcpy.o
BIN
ft_memcpy.o
Binary file not shown.
BIN
ft_memmove.o
BIN
ft_memmove.o
Binary file not shown.
BIN
ft_memset.o
BIN
ft_memset.o
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:24:36 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:24:37 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:27:38 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:28:47 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:29:25 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:29:26 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <limits.h>
|
||||
|
||||
void ft_putnbr_fd(int nb, int fd)
|
||||
{
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr_fd(nb / 10, fd);
|
||||
ft_putchar_fd(nb % 10 + '0', fd);
|
||||
}
|
||||
else if (nb == INT_MIN)
|
||||
{
|
||||
ft_putnbr_fd(nb / 10, fd);
|
||||
ft_putnbr_fd(-(nb % 10), fd);
|
||||
}
|
||||
else if (nb < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
ft_putnbr_fd(-nb, fd);
|
||||
}
|
||||
else
|
||||
ft_putchar_fd(nb % 10 + '0', fd);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:26:11 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:26:11 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
while (*s)
|
||||
ft_putchar_fd(*s++, fd);
|
||||
}
|
|
@ -22,6 +22,8 @@ static size_t split_arr_len(char const *s, char c)
|
|||
{
|
||||
while (*s == c)
|
||||
++s;
|
||||
if (!*s)
|
||||
return (len);
|
||||
++len;
|
||||
while (*s != c && *s)
|
||||
++s;
|
||||
|
@ -50,7 +52,7 @@ char **ft_split(char const *s, char c)
|
|||
char const *start;
|
||||
|
||||
arr_len = split_arr_len(s, c);
|
||||
arr = malloc(sizeof(char *) * (arr_len + 1));
|
||||
arr = malloc(sizeof(*arr) * (arr_len + 1));
|
||||
if (!arr)
|
||||
return (0);
|
||||
idx = 0;
|
||||
|
@ -58,10 +60,12 @@ char **ft_split(char const *s, char c)
|
|||
{
|
||||
while (*s == c)
|
||||
++s;
|
||||
if (!*s)
|
||||
break ;
|
||||
start = s;
|
||||
while (*s != c && *s)
|
||||
++s;
|
||||
arr[idx] = malloc(sizeof(char) * (s - start + 1));
|
||||
arr[idx] = malloc(sizeof(**arr) * (s - start + 1));
|
||||
if (!save_strlcpy(arr, ++idx, start, s - start + 1))
|
||||
return (0);
|
||||
}
|
||||
|
|
BIN
ft_strchr.o
BIN
ft_strchr.o
Binary file not shown.
|
@ -19,7 +19,7 @@ char *ft_strdup(char const *s)
|
|||
size_t len;
|
||||
|
||||
len = ft_strlen(s);
|
||||
s2 = malloc(sizeof(char) * (len + 1));
|
||||
s2 = malloc(sizeof(*s2) * (len + 1));
|
||||
if (!s2)
|
||||
return (0);
|
||||
ft_strlcpy(s2, (char *) s, len + 1);
|
||||
|
|
BIN
ft_strdup.o
BIN
ft_strdup.o
Binary file not shown.
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:47:33 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:47:34 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = -1;
|
||||
while (s[++idx])
|
||||
(f)(idx, &s[idx]);
|
||||
}
|
|
@ -18,7 +18,7 @@ char *ft_strjoin(char const *s1, char const *s2)
|
|||
char *joined_str;
|
||||
|
||||
total_len = ft_strlen(s1) + ft_strlen(s2);
|
||||
joined_str = ft_calloc(total_len + 1, sizeof(char));
|
||||
joined_str = ft_calloc(total_len + 1, sizeof(*joined_str));
|
||||
if (!joined_str)
|
||||
return (0);
|
||||
ft_strlcat(joined_str, s1, total_len + 1);
|
||||
|
|
34
ft_strlcat.c
34
ft_strlcat.c
|
@ -6,7 +6,7 @@
|
|||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/02 20:02:14 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/06/26 20:41:08 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -23,10 +23,10 @@ size_t ft_strlcat(char *dst, char const *src, size_t size)
|
|||
while (src[slen])
|
||||
++slen;
|
||||
idx = 0;
|
||||
while (dst[idx])
|
||||
while (dst[idx] && idx < size)
|
||||
++idx;
|
||||
dlen = idx;
|
||||
if (dlen > size)
|
||||
if (dlen == size)
|
||||
return (slen + size);
|
||||
sidx = 0;
|
||||
size -= dlen;
|
||||
|
@ -35,31 +35,3 @@ size_t ft_strlcat(char *dst, char const *src, size_t size)
|
|||
dst[idx] = 0;
|
||||
return (dlen + slen);
|
||||
}
|
||||
|
||||
/*
|
||||
Alternative implementation
|
||||
size_t ft_strlcat(char *dst, char const *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);
|
||||
}
|
||||
*/
|
||||
|
|
BIN
ft_strlcat.o
BIN
ft_strlcat.o
Binary file not shown.
BIN
ft_strlcpy.o
BIN
ft_strlcpy.o
Binary file not shown.
BIN
ft_strlen.o
BIN
ft_strlen.o
Binary file not shown.
29
ft_strmapi.c
29
ft_strmapi.c
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/03 12:41:34 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/03 12:41:34 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strmapi(char const *s, char (f)(unsigned int, char))
|
||||
{
|
||||
char *str;
|
||||
int idx;
|
||||
|
||||
str = malloc(sizeof(*str) * (ft_strlen(s) + 1));
|
||||
if (!str)
|
||||
return (0);
|
||||
idx = -1;
|
||||
while (s[++idx])
|
||||
str[idx] = (f)(idx, s[idx]);
|
||||
str[idx] = 0;
|
||||
return (str);
|
||||
}
|
BIN
ft_strncmp.o
BIN
ft_strncmp.o
Binary file not shown.
BIN
ft_strnstr.o
BIN
ft_strnstr.o
Binary file not shown.
BIN
ft_strrchr.o
BIN
ft_strrchr.o
Binary file not shown.
|
@ -40,7 +40,7 @@ char *ft_strtrim(char const *s1, char const *set)
|
|||
char *trimmed_str;
|
||||
|
||||
trimmed_len = len_after_trim(s1, set);
|
||||
trimmed_str = malloc(sizeof(char) * (trimmed_len + 1));
|
||||
trimmed_str = malloc(sizeof(*trimmed_str) * (trimmed_len + 1));
|
||||
if (!trimmed_str)
|
||||
return (0);
|
||||
while (ft_char_in_charset(*s1, set))
|
||||
|
|
|
@ -25,7 +25,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
|
|||
;
|
||||
if (!s[idx])
|
||||
{
|
||||
empty = ft_calloc(1, sizeof(char));
|
||||
empty = ft_calloc(1, sizeof(*empty));
|
||||
if (!empty)
|
||||
return (0);
|
||||
return (empty);
|
||||
|
@ -33,7 +33,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
|
|||
real_len = 0;
|
||||
while (++real_len <= len && s[idx + real_len - 1])
|
||||
;
|
||||
substr = malloc(sizeof(char) * real_len);
|
||||
substr = malloc(sizeof(*substr) * real_len);
|
||||
if (!substr)
|
||||
return (0);
|
||||
ft_strlcpy(substr, s + idx, real_len);
|
||||
|
|
BIN
ft_substr.o
BIN
ft_substr.o
Binary file not shown.
BIN
ft_tolower.o
BIN
ft_tolower.o
Binary file not shown.
BIN
ft_toupper.o
BIN
ft_toupper.o
Binary file not shown.
81
libft.h
81
libft.h
|
@ -6,48 +6,67 @@
|
|||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/05/11 11:31:44 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/02 21:25:33 by tischmid ### ########.fr */
|
||||
/* Updated: 2023/06/24 17:16:29 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
# define UINT unsigned int
|
||||
# include <stddef.h>
|
||||
|
||||
int ft_atoi(char const *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(void const *s, int c, size_t n);
|
||||
int ft_memcmp(void const *s1, void const *s2, size_t n);
|
||||
void *ft_memcpy(void *dest, void const *src, size_t n);
|
||||
void *ft_memmove(void *dest, void const *src, size_t n);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
char *ft_strchr(char const *s, int c);
|
||||
char *ft_strdup(char const *s);
|
||||
size_t ft_strlcat(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlcpy(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlen(char const *s);
|
||||
int ft_strncmp(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strnstr(char const *big, char const *little, size_t len);
|
||||
char *ft_strrchr(char const *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);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
int ft_char_in_charset(char c, char const *charset);
|
||||
char **ft_split(char const *s, char c);
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
void *ft_memmove(void *dest, void const *src, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
void *ft_memset(void *s, int c, unsigned long n);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(void const *s1, void const *s2, size_t n);
|
||||
void *ft_memcpy(void *dest, void const *src, size_t n);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isspace(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
char *ft_strnstr(char const *big, char const *little, size_t len);
|
||||
char *ft_strchr(char const *s, int c);
|
||||
char *ft_strrchr(char const *s, int c);
|
||||
char *ft_strdup(char const *s);
|
||||
int ft_strncmp(char const *s1, char const *s2, size_t n);
|
||||
size_t ft_strlen(char const *s);
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
size_t ft_strlcat(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlcat(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlcpy(char *dst, char const *src, size_t size);
|
||||
char *ft_strmapi(char const *s, char (f)(unsigned int, char));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
char *ft_itoa(int n);
|
||||
int ft_atoi(char const *nptr);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int nb, int fd);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
int ft_char_in_charset(char c, char const *charset);
|
||||
UINT ft_abs(int n);
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue