Push libft
125/100 corrected the 14/11/23
This commit is contained in:
commit
7bd66aee5b
45 changed files with 1462 additions and 0 deletions
52
Makefile
Normal file
52
Makefile
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: rparodi <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2023/11/13 19:10:24 by rparodi ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME=libft.a
|
||||
CC=clang
|
||||
CFLAGS=-Wall -Wextra -Werror -g2
|
||||
RM=rm -f
|
||||
LDFLAGS=-L.
|
||||
LDLIBS=-lft
|
||||
SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c ft_isprint.c ft_memchr.c ft_memcmp.c ft_memcpy.c ft_memmove.c ft_memset.c ft_strchr.c ft_strlcat.c ft_strlcpy.c ft_strlen.c ft_strncmp.c ft_strnstr.c ft_strrchr.c ft_tolower.c ft_toupper.c ft_calloc.c ft_strdup.c ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c
|
||||
SRCBonus = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
OBJBonus = $(SRCBonus:.c=.o)
|
||||
|
||||
$(NAME): $(OBJ) $(OBJBonus)
|
||||
ar rc $(NAME) $(OBJ) $(OBJBonus)
|
||||
ranlib $(NAME)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -I. -o $@ -c $? $(CFLAGS)
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
bonus: $(OBJ) $(OBJBonus)
|
||||
ar rc $(NAME) $(OBJ) $(OBJBonus)
|
||||
ranlib $(NAME)
|
||||
|
||||
|
||||
dev: all bonus clean
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ) $(OBJBonus)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
|
||||
re: fclean all bonus
|
||||
|
||||
.PHONY: clean clean
|
||||
|
||||
so: $(OBJ) $(OBJBonus)
|
||||
$(CC) -nostartfiles -fPIC $(CFLAGS) $(SRC) $(SRCBonus)
|
||||
gcc -nostartfiles -shared -o libft.so $(OBJ) $(OBJBonus)
|
||||
54
ft_atoi.c
Normal file
54
ft_atoi.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:22:41 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 12:20:14 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_check_space(int c)
|
||||
{
|
||||
if (c == 32 || (c >= 9 && c <= 13))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_check_sign(const char *nptr, int *i)
|
||||
{
|
||||
while (ft_check_space(nptr[*i]))
|
||||
(*i)++;
|
||||
if (nptr[*i] == '-')
|
||||
{
|
||||
(*i)++;
|
||||
return (-1);
|
||||
}
|
||||
else if (nptr[*i] == '+')
|
||||
(*i)++;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int i;
|
||||
int sign;
|
||||
int number;
|
||||
|
||||
i = 0;
|
||||
sign = ft_check_sign(nptr, &i);
|
||||
number = 0;
|
||||
while (nptr[i])
|
||||
{
|
||||
if (nptr[i] >= '0' && nptr[i] <= '9')
|
||||
number = (number * 10) + nptr[i] - '0';
|
||||
else
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
return (sign * number);
|
||||
}
|
||||
18
ft_bzero.c
Normal file
18
ft_bzero.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:43:13 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 17:25:28 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, 0, n);
|
||||
}
|
||||
31
ft_calloc.c
Normal file
31
ft_calloc.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:47:17 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 14:47:17 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
size_t total;
|
||||
char *to_return;
|
||||
|
||||
if (nmemb == 0 || size == 0)
|
||||
return ((void *)malloc(1));
|
||||
total = nmemb * size;
|
||||
if (total / nmemb != size && total / size != nmemb)
|
||||
return (NULL);
|
||||
to_return = (char *)malloc(total);
|
||||
if (to_return == NULL)
|
||||
to_return = NULL;
|
||||
else
|
||||
ft_bzero(to_return, total);
|
||||
return (to_return);
|
||||
}
|
||||
20
ft_isalnum.c
Normal file
20
ft_isalnum.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 12:47:28 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 10:38:08 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (ft_isalpha(c) || ft_isdigit(c))
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
20
ft_isalpha.c
Normal file
20
ft_isalpha.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:58:37 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 10:38:08 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
22
ft_isascii.c
Normal file
22
ft_isascii.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:04:26 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/08 18:23:33 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c == 0)
|
||||
return (1);
|
||||
if (c > 0 && c <= 127)
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
20
ft_isdigit.c
Normal file
20
ft_isdigit.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 12:44:28 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 10:35:36 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
20
ft_isprint.c
Normal file
20
ft_isprint.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:06:53 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 17:01:22 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
52
ft_itoa.c
Normal file
52
ft_itoa.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:30 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:50:31 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static size_t ft_check_sign(char *str, long *nb)
|
||||
{
|
||||
if ((*nb) == 0)
|
||||
str[0] = '0';
|
||||
if ((*nb) < 0)
|
||||
{
|
||||
str[0] = '-';
|
||||
*nb = -*nb;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
size_t i;
|
||||
size_t modulus;
|
||||
short int maiboyerlpb;
|
||||
char str[13];
|
||||
long nb;
|
||||
|
||||
nb = n;
|
||||
maiboyerlpb = 0;
|
||||
modulus = 1000000000;
|
||||
ft_bzero(str, 13);
|
||||
i = ft_check_sign(str, &nb);
|
||||
while (modulus != 0)
|
||||
{
|
||||
if (nb / modulus != 0 || maiboyerlpb != 0)
|
||||
{
|
||||
str[i++] = (nb / modulus) + 48;
|
||||
maiboyerlpb++;
|
||||
}
|
||||
nb %= modulus;
|
||||
modulus /= 10;
|
||||
}
|
||||
return (ft_strdup(str));
|
||||
}
|
||||
28
ft_lstadd_back.c
Normal file
28
ft_lstadd_back.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:39:56 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 17:11:53 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *tempo;
|
||||
|
||||
if (*lst == NULL)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
tempo = *lst;
|
||||
while (tempo->next != NULL)
|
||||
tempo = tempo->next;
|
||||
tempo->next = new;
|
||||
}
|
||||
24
ft_lstadd_front.c
Normal file
24
ft_lstadd_front.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:40:16 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 17:14:33 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (*lst == NULL)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
25
ft_lstclear.c
Normal file
25
ft_lstclear.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:40:37 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 19:34:19 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *tempo;
|
||||
|
||||
while (*lst)
|
||||
{
|
||||
tempo = (*lst)->next;
|
||||
ft_lstdelone(*lst, del);
|
||||
(*lst) = tempo;
|
||||
}
|
||||
}
|
||||
19
ft_lstdelone.c
Normal file
19
ft_lstdelone.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:42:11 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 18:10:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
22
ft_lstiter.c
Normal file
22
ft_lstiter.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:42:24 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 18:07:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
while (lst != NULL)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
22
ft_lstlast.c
Normal file
22
ft_lstlast.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:42:54 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 17:25:48 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (lst == NULL)
|
||||
return (lst);
|
||||
while (lst->next != NULL)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
37
ft_lstmap.c
Normal file
37
ft_lstmap.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:43:28 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 19:28:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *tempo;
|
||||
t_list *tempo_content;
|
||||
|
||||
tempo_content = ft_lstnew(f(lst->content));
|
||||
if (!tempo_content)
|
||||
return (NULL);
|
||||
tempo = tempo_content;
|
||||
lst = lst->next;
|
||||
while (lst)
|
||||
{
|
||||
tempo_content = ft_lstnew(f(lst->content));
|
||||
if (!tempo_content)
|
||||
{
|
||||
ft_lstclear(&tempo, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&tempo, tempo_content);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (tempo);
|
||||
}
|
||||
26
ft_lstnew.c
Normal file
26
ft_lstnew.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:44:02 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 14:25:12 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *to_return;
|
||||
|
||||
to_return = NULL;
|
||||
to_return = (t_list *)malloc(sizeof(t_list));
|
||||
if (!to_return)
|
||||
return (NULL);
|
||||
to_return->content = content;
|
||||
to_return->next = NULL;
|
||||
return (to_return);
|
||||
}
|
||||
26
ft_lstsize.c
Normal file
26
ft_lstsize.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:44:24 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 12:22:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
while (lst != NULL)
|
||||
{
|
||||
lst = lst->next;
|
||||
count++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
29
ft_memchr.c
Normal file
29
ft_memchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:48:30 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 18:45:57 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)s;
|
||||
while (i < n)
|
||||
{
|
||||
if ((char)c == str[i])
|
||||
return ((void *)str + i);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
31
ft_memcmp.c
Normal file
31
ft_memcmp.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:49:04 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 18:46:15 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *str1;
|
||||
unsigned char *str2;
|
||||
|
||||
i = 0;
|
||||
str1 = (unsigned char *)s1;
|
||||
str2 = (unsigned char *)s2;
|
||||
while (i < n)
|
||||
{
|
||||
if (str1[i] != str2[i])
|
||||
return (str1[i] - str2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
32
ft_memcpy.c
Normal file
32
ft_memcpy.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:49:46 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:14:23 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
const char *s;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!dest && !src)
|
||||
return (NULL);
|
||||
d = (char *)dest;
|
||||
s = (char *)src;
|
||||
while (i < n)
|
||||
{
|
||||
d[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
return ((void *)d);
|
||||
}
|
||||
51
ft_memmove.c
Normal file
51
ft_memmove.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:51:35 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:55:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_checks(char *s, char *d, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (d < s)
|
||||
{
|
||||
while (i < n)
|
||||
{
|
||||
d[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = n;
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
d[i] = s[i];
|
||||
}
|
||||
}
|
||||
return (d);
|
||||
}
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
char *s;
|
||||
|
||||
if (!dest && !src)
|
||||
return (NULL);
|
||||
d = (char *)dest;
|
||||
s = (char *)src;
|
||||
ft_checks(s, d, n);
|
||||
return (dest);
|
||||
}
|
||||
28
ft_memset.c
Normal file
28
ft_memset.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:50:29 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 18:58:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
str = (char *)s;
|
||||
while (i < n)
|
||||
{
|
||||
str[i] = c;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
18
ft_putchar_fd.c
Normal file
18
ft_putchar_fd.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:58:22 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/10 15:31:57 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
19
ft_putendl_fd.c
Normal file
19
ft_putendl_fd.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:59:01 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/10 15:57:53 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
55
ft_putnbr_fd.c
Normal file
55
ft_putnbr_fd.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:59:18 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:13:20 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_check_sign(int n, char *str, size_t *i, int fd)
|
||||
{
|
||||
size_t modulus;
|
||||
short int maiboyerlpb;
|
||||
|
||||
maiboyerlpb = 0;
|
||||
modulus = 1000000000;
|
||||
if (n < 0)
|
||||
{
|
||||
n = -n;
|
||||
str[(*i)] = '-';
|
||||
(*i)++;
|
||||
}
|
||||
while (modulus != 0)
|
||||
{
|
||||
if (n / modulus != 0 || maiboyerlpb != 0)
|
||||
{
|
||||
str[(*i)++] = (n / modulus) + 48;
|
||||
maiboyerlpb++;
|
||||
}
|
||||
n %= modulus;
|
||||
modulus /= 10;
|
||||
}
|
||||
ft_putstr_fd(str, fd);
|
||||
return (n);
|
||||
}
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
size_t i;
|
||||
char str[13];
|
||||
|
||||
i = 0;
|
||||
ft_bzero(str, 13);
|
||||
if (n == 0)
|
||||
ft_putstr_fd("0", fd);
|
||||
else if (n == -2147483648)
|
||||
ft_putstr_fd("-2147483648", fd);
|
||||
else
|
||||
ft_check_sign(n, str, &i, fd);
|
||||
}
|
||||
25
ft_putstr_fd.c
Normal file
25
ft_putstr_fd.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:58:46 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/10 15:57:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
ft_putchar_fd(s[i], fd);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
93
ft_split.c
Normal file
93
ft_split.c
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 12:14:57 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int count_words(const char *str, char sep)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
while (str[i])
|
||||
{
|
||||
while (str[i] == sep && str[i])
|
||||
i++;
|
||||
if (str[i] != sep && str[i])
|
||||
{
|
||||
while (str[i] != sep && str[i])
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
static char *ft_strndup(const char *s, int j)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)malloc((j + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (s[i] && i < j)
|
||||
{
|
||||
str[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
static char **ext_w(char **words_array, const char *str, char sep, int size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (j < size)
|
||||
{
|
||||
while (str[i] == sep && str[i])
|
||||
i++;
|
||||
str = str + i;
|
||||
i = 0;
|
||||
while (str[i] != sep && str[i])
|
||||
i++;
|
||||
words_array[j++] = ft_strndup(str, i);
|
||||
str = str + i;
|
||||
i = 0;
|
||||
}
|
||||
words_array[j] = 0;
|
||||
return (words_array);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
int size;
|
||||
char **words_array;
|
||||
|
||||
size = count_words(s, c);
|
||||
words_array = (char **)malloc(sizeof(char *) * (size + 1));
|
||||
if (!words_array)
|
||||
return (NULL);
|
||||
if (size == 0)
|
||||
{
|
||||
words_array[0] = NULL;
|
||||
return (words_array);
|
||||
}
|
||||
words_array = ext_w(words_array, s, c, size);
|
||||
return (words_array);
|
||||
}
|
||||
29
ft_strchr.c
Normal file
29
ft_strchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:32:19 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/09 12:08:01 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (c == 0)
|
||||
return ((char *)s + ft_strlen(s));
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
if (s[i] == (char)c)
|
||||
return ((char *)s + i);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
26
ft_strdup.c
Normal file
26
ft_strdup.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:53:59 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:02:09 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
size_t len;
|
||||
char *to_return;
|
||||
|
||||
len = ft_strlen(s) + 1;
|
||||
to_return = (char *)malloc(sizeof(char) * len);
|
||||
if (!to_return)
|
||||
return (NULL);
|
||||
ft_strlcpy(to_return, s, len);
|
||||
return (to_return);
|
||||
}
|
||||
25
ft_striteri.c
Normal file
25
ft_striteri.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:57:34 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/11 17:26:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
f(i, s + i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
39
ft_strjoin.c
Normal file
39
ft_strjoin.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:55:15 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/09 17:47:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
size_t i;
|
||||
size_t save_i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)malloc((ft_strlen(s1) + ft_strlen(s2)) + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
str[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
save_i = i;
|
||||
i = 0;
|
||||
while (s2[i] != '\0')
|
||||
{
|
||||
str[save_i + i] = s2[i];
|
||||
i++;
|
||||
}
|
||||
str[i + save_i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
53
ft_strlcat.c
Normal file
53
ft_strlcat.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 22:28:26 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 11:45:52 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static size_t ft_strnlen(char *dest, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < size)
|
||||
{
|
||||
if (dest[i] == '\0')
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t destlen;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
destlen = ft_strnlen(dest, size);
|
||||
while (i < size && dest[i])
|
||||
i++;
|
||||
if (i == size)
|
||||
return (i + ft_strlen(src));
|
||||
while (src[j])
|
||||
{
|
||||
if (j < size - destlen - 1)
|
||||
{
|
||||
dest[i] = src[j];
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (destlen + j);
|
||||
}
|
||||
31
ft_strlcpy.c
Normal file
31
ft_strlcpy.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:16:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] && i + 1 < size)
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
if (size > 0)
|
||||
{
|
||||
dst[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (ft_strlen(src));
|
||||
}
|
||||
23
ft_strlen.c
Normal file
23
ft_strlen.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:56:24 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/08 12:37:09 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
34
ft_strmapi.c
Normal file
34
ft_strmapi.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:57 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:49:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
size_t i;
|
||||
size_t len;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
len = ft_strlen(s);
|
||||
str = (char *)malloc(len + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
else
|
||||
ft_bzero((char *)str, len + 1);
|
||||
while (i < len)
|
||||
{
|
||||
str[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
31
ft_strncmp.c
Normal file
31
ft_strncmp.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/09 13:16:39 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
int diff;
|
||||
|
||||
i = 0;
|
||||
while ((s1[i] || s2[i]) && i < n)
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
{
|
||||
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||
return (diff);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
37
ft_strnstr.c
Normal file
37
ft_strnstr.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:57:44 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:17:49 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (len == 0 && (!big || !little))
|
||||
return (NULL);
|
||||
if (!little[i])
|
||||
return ((char *)big);
|
||||
while (big[i] && i < len)
|
||||
{
|
||||
j = 0;
|
||||
while (i + j < len && little[j] == big[i + j])
|
||||
{
|
||||
j++;
|
||||
if (little[j] == '\0')
|
||||
return ((char *)(big + i));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
29
ft_strrchr.c
Normal file
29
ft_strrchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:58:22 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/11 18:46:54 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = ft_strlen(s);
|
||||
while (i > 0)
|
||||
{
|
||||
if (s[i] == c % 256)
|
||||
return ((char *)s + i);
|
||||
i--;
|
||||
}
|
||||
if (s[i] == c % 256)
|
||||
return ((char *)s + i);
|
||||
return (NULL);
|
||||
}
|
||||
40
ft_strtrim.c
Normal file
40
ft_strtrim.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:55:44 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:08:51 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t k;
|
||||
char *str;
|
||||
|
||||
if (!s1)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (ft_strchr(set, s1[i]) != NULL && s1[i])
|
||||
i++;
|
||||
if (i == ft_strlen(s1))
|
||||
return (ft_strdup(""));
|
||||
j = ft_strlen(s1);
|
||||
while (ft_strrchr(set, s1[j - 1]) != NULL && j > i)
|
||||
j--;
|
||||
str = (char *)malloc(j - i + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
k = 0;
|
||||
while (i < j)
|
||||
str[k++] = s1[i++];
|
||||
str[k] = '\0';
|
||||
return (str);
|
||||
}
|
||||
32
ft_substr.c
Normal file
32
ft_substr.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:08:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
char *str;
|
||||
|
||||
i = start;
|
||||
if (start >= ft_strlen(s))
|
||||
return (ft_strdup(""));
|
||||
if (len + start > (ft_strlen(s)))
|
||||
len = ft_strlen(s) - start;
|
||||
j = 0;
|
||||
str = (char *)malloc(len + 1);
|
||||
if (!str || !s)
|
||||
return (free(str), ft_strdup(""));
|
||||
ft_strlcpy(str, s + start, len + 1);
|
||||
return (str);
|
||||
}
|
||||
20
ft_tolower.c
Normal file
20
ft_tolower.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 10:38:54 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 16:59:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 32;
|
||||
return (c);
|
||||
}
|
||||
20
ft_toupper.c
Normal file
20
ft_toupper.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 10:44:26 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/08 18:08:21 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
c -= 32;
|
||||
return (c);
|
||||
}
|
||||
74
libft.h
Normal file
74
libft.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:14:57 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 18:58:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# define INT_MAX 2147483647
|
||||
# define INT_MIN -2147483648
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
size_t ft_strlen(const char *s);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
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);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
int ft_atoi(const char *nptr);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
char *ft_strdup(const char *s);
|
||||
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);
|
||||
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);
|
||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
t_list *ft_lstnew(void *content);
|
||||
int ft_lstsize(t_list *lst);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue