Ca marche bien
This commit is contained in:
commit
cdc4eb5d5f
60
Makefile
Normal file
60
Makefile
Normal file
@ -0,0 +1,60 @@
|
||||
CLIENT_SRC = client_src/main.c
|
||||
SERVER_SRC = server_src/main.c
|
||||
|
||||
CLIENT_OBJ = ${CLIENT_SRC:.c=.o}
|
||||
SERVER_OBJ = ${SERVER_SRC:.c=.o}
|
||||
|
||||
CC = clang
|
||||
CFLAGS = -Werror -Wall -Wextra -g
|
||||
LIBS = libftx/libftx.a
|
||||
|
||||
CLIENT_NAME = client
|
||||
SERVER_NAME = server
|
||||
|
||||
%.o: %.c
|
||||
${CC} ${CFLAGS} -c $< -o $@
|
||||
|
||||
all: ${CLIENT_NAME} ${SERVER_NAME}
|
||||
|
||||
${CLIENT_NAME}: ${CLIENT_OBJ}
|
||||
make -C libftx
|
||||
${CC} ${CLIENT_OBJ} -o ${CLIENT_NAME} ${LIBS}
|
||||
|
||||
${SERVER_NAME}: ${SERVER_OBJ}
|
||||
make -C libftx
|
||||
${CC} ${SERVER_OBJ} -o ${SERVER_NAME} ${LIBS}
|
||||
|
||||
client_clean:
|
||||
make -C libftx clean
|
||||
rm -f ${CLIENT_OBJ}
|
||||
|
||||
server_clean:
|
||||
make -C libftx clean
|
||||
rm -f ${SERVER_OBJ}
|
||||
|
||||
clean:
|
||||
make -C libftx clean
|
||||
rm -f ${SERVER_OBJ}
|
||||
rm -f ${CLIENT_OBJ}
|
||||
|
||||
client_fclean:
|
||||
make -C libftx fclean
|
||||
rm -f ${CLIENT_NAME}
|
||||
|
||||
server_fclean:
|
||||
make -C libftx fclean
|
||||
rm -f ${SERVER_NAME}
|
||||
|
||||
fclean:
|
||||
make -C libftx fclean
|
||||
rm -f ${SERVER_NAME}
|
||||
rm -f ${CLIENT_NAME}
|
||||
|
||||
server_re: server_fclean
|
||||
${SERVER_NAME}
|
||||
|
||||
client_re: client_fclean client
|
||||
|
||||
re: client_re server
|
||||
|
||||
.PHONY: all clean fclean re client_re client_clean client_fclean server_re server_clean server_fclean
|
52
client_src/main.c
Normal file
52
client_src/main.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/20 17:06:30 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/20 18:36:25 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <signal.h>
|
||||
#include "../libftx/libftx.h"
|
||||
|
||||
void ft_char2signal(int pid, char c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = sizeof(char) * 8;
|
||||
while (i > 0)
|
||||
{
|
||||
if ((c >> (i - 1)) & 1)
|
||||
kill(pid, SIGUSR2);
|
||||
else
|
||||
kill(pid, SIGUSR1);
|
||||
i--;
|
||||
usleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int pid;
|
||||
size_t i;
|
||||
|
||||
if (ac != 3 || !ft_isnum(av[1]))
|
||||
{
|
||||
ft_printf("Argument error !");
|
||||
return (1);
|
||||
}
|
||||
pid = ft_atoi(av[1]);
|
||||
kill(pid, SIGUSR2);
|
||||
i = 0;
|
||||
while (av[2][i] != '\0')
|
||||
{
|
||||
ft_char2signal(pid, av[2][i]);
|
||||
i++;
|
||||
}
|
||||
ft_char2signal(pid, '\0');
|
||||
return (0);
|
||||
}
|
BIN
client_src/main.o
Normal file
BIN
client_src/main.o
Normal file
Binary file not shown.
35
libftx/Makefile
Normal file
35
libftx/Makefile
Normal file
@ -0,0 +1,35 @@
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
NAME = libftx.a
|
||||
|
||||
LIBS = libft/libft.a gnl/get_next_line.a printf/ft_printf.a extra/extra.a
|
||||
|
||||
CC = clang
|
||||
|
||||
FLAG = -Wall -Wextra -Werror
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
${NAME}: ${OBJ}
|
||||
make -C extra
|
||||
make -C libft
|
||||
make -C gnl
|
||||
make -C printf
|
||||
ar -rcT $(NAME) $(LIBS)
|
||||
|
||||
clean:
|
||||
make -C extra clean
|
||||
make -C libft clean
|
||||
make -C gnl clean
|
||||
make -C printf clean
|
||||
|
||||
fclean: clean
|
||||
rm -f ${NAME}
|
||||
make -C extra fclean
|
||||
make -C libft fclean
|
||||
make -C printf fclean
|
||||
make -C gnl fclean
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
39
libftx/extra/Makefile
Normal file
39
libftx/extra/Makefile
Normal file
@ -0,0 +1,39 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||
# Updated: 2023/01/20 17:13:55 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
CC = clang
|
||||
|
||||
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_realloc.c ft_ultoa_base.c ft_isnum.c
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
NAME = extra.a
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra -g
|
||||
|
||||
%.o: %.c extra.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
ar -rc $(NAME) $(OBJS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(BOBJS)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all bonus clean fclean re
|
BIN
libftx/extra/extra.a
Normal file
BIN
libftx/extra/extra.a
Normal file
Binary file not shown.
38
libftx/extra/extra.h
Normal file
38
libftx/extra/extra.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* extra.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/20 17:14:30 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef EXTRA_H
|
||||
# define EXTRA_H
|
||||
# include <stdarg.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <limits.h>
|
||||
# include "../libft/libft.h"
|
||||
|
||||
int ft_isnum(char *str);
|
||||
char *ft_ultoa_base(unsigned long long n, char *base);
|
||||
char *get_next_line(int fd);
|
||||
size_t ft_random_generator(size_t start, size_t stop);
|
||||
void ft_freer_tab_ultimate(size_t len, ...);
|
||||
void ft_freer_ultimate(size_t len, ...);
|
||||
char *ft_strgen(char c, size_t len);
|
||||
char *ft_strfjoin(char *s1, char *s2);
|
||||
char *ft_strmerger(size_t arg_len, ...);
|
||||
int ft_is_in(char *str, char c);
|
||||
void *ft_realloc(void *tab, size_t size, size_t new_size, int bytes);
|
||||
char *ft_strndup(char *src, size_t n);
|
||||
ssize_t ft_strchri(char *str, char c);
|
||||
int ft_contain_only_str(char *str, char *to_find);
|
||||
int ft_contain_only(char *str, char c);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
#endif
|
41
libftx/extra/ft_contain_only.c
Normal file
41
libftx/extra/ft_contain_only.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_contain_only.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/12 16:28:20 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/12 16:31:22 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_contain_only(char *str, char c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] != c)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_contain_only_str(char *str, char *to_find)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (!ft_is_in(to_find, str[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
BIN
libftx/extra/ft_contain_only.o
Normal file
BIN
libftx/extra/ft_contain_only.o
Normal file
Binary file not shown.
58
libftx/extra/ft_freer.c
Normal file
58
libftx/extra/ft_freer.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_freer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/08 15:01:40 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/09 17:57:52 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
void ft_freer_ultimate(size_t len, ...)
|
||||
{
|
||||
va_list va;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
va_start(va, len);
|
||||
while (i < len)
|
||||
{
|
||||
free(va_arg(va, char *));
|
||||
i++;
|
||||
}
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void ft_freer_tab(char **tab)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (tab == NULL)
|
||||
return ;
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
{
|
||||
free(tab[i]);
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
}
|
||||
|
||||
void ft_freer_tab_ultimate(size_t len, ...)
|
||||
{
|
||||
va_list va;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
va_start(va, len);
|
||||
while (i < len)
|
||||
{
|
||||
ft_freer_tab(va_arg(va, char **));
|
||||
i++;
|
||||
}
|
||||
va_end(va);
|
||||
}
|
BIN
libftx/extra/ft_freer.o
Normal file
BIN
libftx/extra/ft_freer.o
Normal file
Binary file not shown.
27
libftx/extra/ft_is_in.c
Normal file
27
libftx/extra/ft_is_in.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_in.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 20:29:53 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/08 12:15:08 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_is_in(char *str, char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == c)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
BIN
libftx/extra/ft_is_in.o
Normal file
BIN
libftx/extra/ft_is_in.o
Normal file
Binary file not shown.
38
libftx/extra/ft_isnum.c
Normal file
38
libftx/extra/ft_isnum.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/08 18:43:06 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/20 17:14:08 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_isnum(char *str)
|
||||
{
|
||||
long int i;
|
||||
int sign;
|
||||
|
||||
sign = 1;
|
||||
if (*str == '-')
|
||||
sign = -1;
|
||||
i = 0;
|
||||
if (*str == '-' || *str == '+')
|
||||
str++;
|
||||
if (*str == '\0')
|
||||
return (0);
|
||||
while (*str != '\0')
|
||||
{
|
||||
i = i * 10 + *str - '0';
|
||||
if (i * sign > INT_MAX || INT_MIN > i * sign)
|
||||
return (0);
|
||||
if (!(*str >= '0' && *str <= '9'))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
BIN
libftx/extra/ft_isnum.o
Normal file
BIN
libftx/extra/ft_isnum.o
Normal file
Binary file not shown.
38
libftx/extra/ft_random_generator.c
Normal file
38
libftx/extra/ft_random_generator.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_random_generator.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/09 18:43:27 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/09 20:09:33 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
size_t ft_random_generator(size_t start, size_t stop)
|
||||
{
|
||||
int fd;
|
||||
char *line;
|
||||
int sum;
|
||||
size_t i;
|
||||
|
||||
fd = open("/dev/random", O_RDONLY);
|
||||
if (fd == -1)
|
||||
return (0);
|
||||
line = ft_calloc(sizeof(char), 10001);
|
||||
if (line == NULL)
|
||||
return (0);
|
||||
read(fd, line, 10000);
|
||||
sum = 0;
|
||||
i = 0;
|
||||
while (i < ft_strlen(line))
|
||||
{
|
||||
sum += (unsigned int) line[i];
|
||||
i++;
|
||||
}
|
||||
free(line);
|
||||
return (sum % (stop - start));
|
||||
}
|
BIN
libftx/extra/ft_random_generator.o
Normal file
BIN
libftx/extra/ft_random_generator.o
Normal file
Binary file not shown.
31
libftx/extra/ft_realloc.c
Normal file
31
libftx/extra/ft_realloc.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_realloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 18:58:48 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/20 16:22:50 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
void *ft_realloc(void *tab, size_t size, size_t new_size, int bytes)
|
||||
{
|
||||
char *new;
|
||||
size_t i;
|
||||
|
||||
new = ft_calloc(new_size, bytes);
|
||||
if (new == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < size * bytes && tab != NULL)
|
||||
{
|
||||
new[i] = ((char *) tab)[i];
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
return (new);
|
||||
}
|
BIN
libftx/extra/ft_realloc.o
Normal file
BIN
libftx/extra/ft_realloc.o
Normal file
Binary file not shown.
27
libftx/extra/ft_strchri.c
Normal file
27
libftx/extra/ft_strchri.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/05 19:22:58 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/10 18:30:35 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
ssize_t ft_strchri(char *str, char c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (str == NULL)
|
||||
return (-1);
|
||||
i = 0;
|
||||
while (str[i] != c && str[i] != '\0')
|
||||
i++;
|
||||
if (str[i] == '\0')
|
||||
return (-1);
|
||||
return (i);
|
||||
}
|
BIN
libftx/extra/ft_strchri.o
Normal file
BIN
libftx/extra/ft_strchri.o
Normal file
Binary file not shown.
23
libftx/extra/ft_strcmp.c
Normal file
23
libftx/extra/ft_strcmp.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 19:20:47 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/05 13:20:20 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] == s2[i] && s1[i] != '\0')
|
||||
i++;
|
||||
return (s1[i] - s2[i]);
|
||||
}
|
BIN
libftx/extra/ft_strcmp.o
Normal file
BIN
libftx/extra/ft_strcmp.o
Normal file
Binary file not shown.
42
libftx/extra/ft_strfjoin.c
Normal file
42
libftx/extra/ft_strfjoin.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strfjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 14:06:04 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/10 18:29:59 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
char *ft_strfjoin(char *s1, char *s2)
|
||||
{
|
||||
ssize_t i;
|
||||
ssize_t y;
|
||||
char *out;
|
||||
|
||||
out = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
if (s1 != NULL)
|
||||
{
|
||||
i = -1;
|
||||
while (s1[++i] != '\0')
|
||||
out[i] = s1[i];
|
||||
}
|
||||
free(s1);
|
||||
y = 0;
|
||||
if (s2 != NULL)
|
||||
{
|
||||
y = -1;
|
||||
while (s2[++y] != '\0')
|
||||
out[i + y] = s2[y];
|
||||
}
|
||||
free(s2);
|
||||
out[i + y] = '\0';
|
||||
return (out);
|
||||
}
|
BIN
libftx/extra/ft_strfjoin.o
Normal file
BIN
libftx/extra/ft_strfjoin.o
Normal file
Binary file not shown.
31
libftx/extra/ft_strgen.c
Normal file
31
libftx/extra/ft_strgen.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strgen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/08 12:32:52 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/09 18:04:31 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
char *ft_strgen(char c, size_t len)
|
||||
{
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
out = ft_calloc((len + 1), sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
out[i] = c;
|
||||
i++;
|
||||
}
|
||||
out[len] = '\0';
|
||||
return (out);
|
||||
}
|
BIN
libftx/extra/ft_strgen.o
Normal file
BIN
libftx/extra/ft_strgen.o
Normal file
Binary file not shown.
33
libftx/extra/ft_strmerger.c
Normal file
33
libftx/extra/ft_strmerger.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmerger.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/04 15:09:15 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/04 15:24:17 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
char *ft_strmerger(size_t arg_len, ...)
|
||||
{
|
||||
va_list va;
|
||||
char *out;
|
||||
char *temp;
|
||||
|
||||
va_start(va, arg_len);
|
||||
out = ft_strjoin(va_arg(va, char *), va_arg(va, char *));
|
||||
while (arg_len > 2)
|
||||
{
|
||||
temp = ft_strjoin(out, va_arg(va, char *));
|
||||
free(out);
|
||||
if (temp == NULL)
|
||||
return (NULL);
|
||||
out = temp;
|
||||
arg_len--;
|
||||
}
|
||||
return (out);
|
||||
}
|
BIN
libftx/extra/ft_strmerger.o
Normal file
BIN
libftx/extra/ft_strmerger.o
Normal file
Binary file not shown.
32
libftx/extra/ft_strndup.c
Normal file
32
libftx/extra/ft_strndup.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strndup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/26 00:55:44 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/05 19:27:03 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
char *ft_strndup(char *src, size_t n)
|
||||
{
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
if (src[0] == '\0')
|
||||
return (NULL);
|
||||
out = ft_calloc(n + 1, sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (src[i] != '\0' && i < n)
|
||||
{
|
||||
out[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
}
|
BIN
libftx/extra/ft_strndup.o
Normal file
BIN
libftx/extra/ft_strndup.o
Normal file
Binary file not shown.
BIN
libftx/extra/ft_ultoa.o
Normal file
BIN
libftx/extra/ft_ultoa.o
Normal file
Binary file not shown.
89
libftx/extra/ft_ultoa_base.c
Normal file
89
libftx/extra/ft_ultoa_base.c
Normal file
@ -0,0 +1,89 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultoa_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 13:49:45 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/19 13:01:09 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
static size_t ft_str_size(unsigned long long n, size_t base_size)
|
||||
{
|
||||
size_t size;
|
||||
|
||||
size = 1;
|
||||
if (n == 0)
|
||||
return (2);
|
||||
while (n != 0)
|
||||
{
|
||||
n = n / base_size;
|
||||
size++;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
|
||||
static int ft_isdup(char *str)
|
||||
{
|
||||
char c;
|
||||
size_t i;
|
||||
|
||||
while (*str != 0)
|
||||
{
|
||||
c = *str;
|
||||
i = 1;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if (str[i] == c)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static size_t ft_base_size(char *base)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (ft_isdup(base))
|
||||
return (0);
|
||||
len = ft_strlen(base);
|
||||
if (len < 2)
|
||||
return (0);
|
||||
return (len);
|
||||
}
|
||||
|
||||
char *ft_ultoa_base(unsigned long long n, char *base)
|
||||
{
|
||||
size_t base_size;
|
||||
int str_size;
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
if (base == NULL)
|
||||
return (NULL);
|
||||
base_size = ft_base_size(base);
|
||||
if (base_size == 0)
|
||||
return (NULL);
|
||||
str_size = ft_str_size(n, base_size);
|
||||
out = ft_calloc(str_size + 1, sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
out[0] = base[0];
|
||||
while (n != 0)
|
||||
{
|
||||
out[str_size - 2 - i] = base[n % base_size];
|
||||
n /= base_size;
|
||||
i++;
|
||||
}
|
||||
out[str_size - 1] = '\0';
|
||||
return (out);
|
||||
}
|
BIN
libftx/extra/ft_ultoa_base.o
Normal file
BIN
libftx/extra/ft_ultoa_base.o
Normal file
Binary file not shown.
39
libftx/gnl/Makefile
Normal file
39
libftx/gnl/Makefile
Normal file
@ -0,0 +1,39 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/12/14 15:49:18 by cchauvet #+# #+# #
|
||||
# Updated: 2023/01/05 19:22:40 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
SRCS = get_next_line.c
|
||||
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
|
||||
NAME = get_next_line.a
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra -g
|
||||
|
||||
CC = clang
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
ar -rc $(NAME) $(OBJS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(BOBJS)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all bonus clean fclean re
|
BIN
libftx/gnl/get_next_line.a
Normal file
BIN
libftx/gnl/get_next_line.a
Normal file
Binary file not shown.
104
libftx/gnl/get_next_line.c
Normal file
104
libftx/gnl/get_next_line.c
Normal file
@ -0,0 +1,104 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/26 00:52:47 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/05 13:07:10 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
|
||||
char *ft_getstash(int fd)
|
||||
{
|
||||
char *str;
|
||||
int readed;
|
||||
|
||||
str = ft_calloc(BUFFER_SIZE + 1, sizeof(char));
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
readed = read(fd, str, BUFFER_SIZE);
|
||||
if (readed < 1)
|
||||
{
|
||||
free(str);
|
||||
return (NULL);
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
char *ft_getline(int fd)
|
||||
{
|
||||
char *stash;
|
||||
char *buf;
|
||||
|
||||
stash = NULL;
|
||||
buf = NULL;
|
||||
while (ft_strchri(stash, '\n') == -1)
|
||||
{
|
||||
buf = ft_getstash(fd);
|
||||
if (buf == NULL)
|
||||
return (stash);
|
||||
stash = ft_strfjoin(stash, buf);
|
||||
if (stash == NULL)
|
||||
return (NULL);
|
||||
}
|
||||
return (stash);
|
||||
}
|
||||
|
||||
char *ft_getreturn(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
i = ft_strchri(str, '\n') + 1;
|
||||
if (i == 0)
|
||||
i = ft_strlen(str);
|
||||
return (ft_strndup(str, i));
|
||||
}
|
||||
|
||||
char *ft_getextra(char *str)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
i = ft_strchri(str, '\n') + 1;
|
||||
if (i == 0)
|
||||
return (NULL);
|
||||
j = ft_strlen(str + i);
|
||||
return (ft_strndup(str + i, j));
|
||||
}
|
||||
|
||||
char *get_next_line(int fd)
|
||||
{
|
||||
static char *stash = NULL;
|
||||
char *buf1;
|
||||
char *buf2;
|
||||
|
||||
buf2 = stash;
|
||||
if (ft_strchri(stash, '\n') == -1)
|
||||
{
|
||||
buf1 = ft_getline(fd);
|
||||
buf2 = ft_strfjoin(stash, buf1);
|
||||
if (buf2 == NULL)
|
||||
{
|
||||
free(buf1);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
buf1 = ft_getreturn(buf2);
|
||||
stash = ft_getextra(buf2);
|
||||
free(buf2);
|
||||
if (buf1 == NULL)
|
||||
{
|
||||
free(stash);
|
||||
free(buf1);
|
||||
return (NULL);
|
||||
}
|
||||
return (buf1);
|
||||
}
|
25
libftx/gnl/get_next_line.h
Normal file
25
libftx/gnl/get_next_line.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/11/14 15:38:06 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/10 18:26:56 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GET_NEXT_LINE_H
|
||||
# define GET_NEXT_LINE_H
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# ifndef BUFFER_SIZE
|
||||
# define BUFFER_SIZE 42
|
||||
# endif
|
||||
# include "../libft/libft.h"
|
||||
# include "../extra/extra.h"
|
||||
|
||||
char *get_next_line(int fd);
|
||||
|
||||
#endif
|
BIN
libftx/gnl/get_next_line.o
Normal file
BIN
libftx/gnl/get_next_line.o
Normal file
Binary file not shown.
BIN
libftx/gnl/get_next_line_utils.o
Normal file
BIN
libftx/gnl/get_next_line_utils.o
Normal file
Binary file not shown.
87
libftx/libft/Makefile
Normal file
87
libftx/libft/Makefile
Normal file
@ -0,0 +1,87 @@
|
||||
:# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
|
||||
# Updated: 2023/01/05 17:44:37 by cchauvet ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
CC = clang
|
||||
|
||||
SRCS = ft_isalpha.c \
|
||||
ft_isdigit.c \
|
||||
ft_isalnum.c \
|
||||
ft_isascii.c \
|
||||
ft_isprint.c \
|
||||
ft_strlen.c \
|
||||
ft_memset.c \
|
||||
ft_bzero.c \
|
||||
ft_memcpy.c \
|
||||
ft_memmove.c \
|
||||
ft_strlcpy.c \
|
||||
ft_strlcat.c \
|
||||
ft_toupper.c \
|
||||
ft_tolower.c \
|
||||
ft_strchr.c \
|
||||
ft_strrchr.c \
|
||||
ft_strncmp.c \
|
||||
ft_memchr.c \
|
||||
ft_memcmp.c \
|
||||
ft_strnstr.c \
|
||||
ft_atoi.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
|
||||
|
||||
BSRCS = 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
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
BOBJS = $(BSRCS:.c=.o)
|
||||
|
||||
NAME = libft.a
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra -g
|
||||
|
||||
%.o: %.c libft.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
ar -rc $(NAME) $(OBJS)
|
||||
|
||||
bonus: $(OBJS) $(BOBJS)
|
||||
ar -rc $(NAME) $(OBJS) $(BOBJS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(BOBJS)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all bonus clean fclean re
|
39
libftx/libft/ft_atoi.c
Normal file
39
libftx/libft/ft_atoi.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/28 18:15:04 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
char *str;
|
||||
int out;
|
||||
int sign;
|
||||
|
||||
str = (char *) nptr;
|
||||
out = 0;
|
||||
while (*str == ' ' || *str == '\f' || *str == '\v' || *str == '\t'
|
||||
|| *str == '\r' || *str == '\n')
|
||||
str++;
|
||||
sign = 1;
|
||||
if (*str == '-' || *str == '+')
|
||||
{
|
||||
if (*str == '-')
|
||||
sign = -1;
|
||||
str++;
|
||||
}
|
||||
while (ft_isdigit(*str))
|
||||
{
|
||||
out = 10 * out + *str - 48;
|
||||
str++;
|
||||
}
|
||||
return (out * sign);
|
||||
}
|
BIN
libftx/libft/ft_atoi.o
Normal file
BIN
libftx/libft/ft_atoi.o
Normal file
Binary file not shown.
18
libftx/libft/ft_bzero.c
Normal file
18
libftx/libft/ft_bzero.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 09:40:13 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/27 09:41:02 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, 0, n);
|
||||
}
|
BIN
libftx/libft/ft_bzero.o
Normal file
BIN
libftx/libft/ft_bzero.o
Normal file
Binary file not shown.
26
libftx/libft/ft_calloc.c
Normal file
26
libftx/libft/ft_calloc.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 16:09:01 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/28 17:31:12 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *tab;
|
||||
|
||||
if (nmemb != 0 && (size_t)(nmemb * size) / nmemb != size)
|
||||
return (NULL);
|
||||
tab = malloc(nmemb * size);
|
||||
if (tab == NULL)
|
||||
return (NULL);
|
||||
ft_bzero(tab, nmemb * size);
|
||||
return (tab);
|
||||
}
|
BIN
libftx/libft/ft_calloc.o
Normal file
BIN
libftx/libft/ft_calloc.o
Normal file
Binary file not shown.
22
libftx/libft/ft_isalnum.c
Normal file
22
libftx/libft/ft_isalnum.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 11:15:04 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/28 17:31:44 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (('9' >= c && c >= '0')
|
||||
|| ('z' >= c && c >= 'a')
|
||||
|| ('Z' >= c && c >= 'A'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
BIN
libftx/libft/ft_isalnum.o
Normal file
BIN
libftx/libft/ft_isalnum.o
Normal file
Binary file not shown.
20
libftx/libft/ft_isalpha.c
Normal file
20
libftx/libft/ft_isalpha.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 11:15:04 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/27 11:04:58 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if (('z' >= c && c >= 'a') || ('Z' >= c && c >= 'A'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
BIN
libftx/libft/ft_isalpha.o
Normal file
BIN
libftx/libft/ft_isalpha.o
Normal file
Binary file not shown.
18
libftx/libft/ft_isascii.c
Normal file
18
libftx/libft/ft_isascii.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 11:57:55 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/26 13:33:50 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && 127 >= c)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
BIN
libftx/libft/ft_isascii.o
Normal file
BIN
libftx/libft/ft_isascii.o
Normal file
Binary file not shown.
20
libftx/libft/ft_isdigit.c
Normal file
20
libftx/libft/ft_isdigit.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 11:15:04 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/27 11:09:19 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if ('9' >= c && c >= '0')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
BIN
libftx/libft/ft_isdigit.o
Normal file
BIN
libftx/libft/ft_isdigit.o
Normal file
Binary file not shown.
18
libftx/libft/ft_isprint.c
Normal file
18
libftx/libft/ft_isprint.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 11:52:31 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/28 15:05:17 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
return (32 <= c && c < 127);
|
||||
}
|
BIN
libftx/libft/ft_isprint.o
Normal file
BIN
libftx/libft/ft_isprint.o
Normal file
Binary file not shown.
55
libftx/libft/ft_itoa.c
Normal file
55
libftx/libft/ft_itoa.c
Normal file
@ -0,0 +1,55 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 13:49:45 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/09 13:51:09 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_nb_digit(int n)
|
||||
{
|
||||
int out;
|
||||
|
||||
out = 0;
|
||||
while (n)
|
||||
{
|
||||
n /= 10;
|
||||
out++;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *out;
|
||||
unsigned int nb[2];
|
||||
|
||||
if (!n)
|
||||
return (ft_strdup("0"));
|
||||
nb[0] = ft_nb_digit(n);
|
||||
if (n < 0)
|
||||
{
|
||||
nb[1] = -n;
|
||||
nb[0]++;
|
||||
}
|
||||
else
|
||||
nb[1] = n;
|
||||
out = malloc(sizeof(char) * (nb[0] + 1));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
out[nb[0]--] = 0;
|
||||
if (n < 0)
|
||||
out[0] = '-';
|
||||
while (nb[1])
|
||||
{
|
||||
out[nb[0]--] = nb[1] % 10 + 48;
|
||||
nb[1] /= 10;
|
||||
}
|
||||
return (out);
|
||||
}
|
BIN
libftx/libft/ft_itoa.o
Normal file
BIN
libftx/libft/ft_itoa.o
Normal file
Binary file not shown.
26
libftx/libft/ft_lstadd_back.c
Normal file
26
libftx/libft/ft_lstadd_back.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 23:58:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/26 18:06:00 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *last;
|
||||
|
||||
if (lst == NULL || new == NULL)
|
||||
return ;
|
||||
last = ft_lstlast(*lst);
|
||||
if (last == NULL)
|
||||
*lst = new;
|
||||
else
|
||||
last->next = new;
|
||||
}
|
21
libftx/libft/ft_lstadd_front.c
Normal file
21
libftx/libft/ft_lstadd_front.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 23:50:03 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/30 01:08:27 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (new == NULL)
|
||||
return ;
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
27
libftx/libft/ft_lstclear.c
Normal file
27
libftx/libft/ft_lstclear.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/30 00:01:05 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/21 14:55:37 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *next;
|
||||
|
||||
if (lst == NULL || del == NULL)
|
||||
return ;
|
||||
while (*lst != NULL)
|
||||
{
|
||||
next = (*lst)->next;
|
||||
ft_lstdelone(*lst, del);
|
||||
*lst = next;
|
||||
}
|
||||
}
|
25
libftx/libft/ft_lstdelone.c
Normal file
25
libftx/libft/ft_lstdelone.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/30 00:02:55 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/05 21:01:41 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
if (del == NULL || lst == NULL)
|
||||
return ;
|
||||
if (lst != NULL)
|
||||
{
|
||||
if (lst->content != NULL)
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
}
|
24
libftx/libft/ft_lstiter.c
Normal file
24
libftx/libft/ft_lstiter.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/30 00:05:43 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/05 20:58:18 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (f == NULL)
|
||||
return ;
|
||||
while (lst != NULL)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
22
libftx/libft/ft_lstlast.c
Normal file
22
libftx/libft/ft_lstlast.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 23:55:52 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/30 01:20:18 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (lst == NULL)
|
||||
return (NULL);
|
||||
while (lst->next != NULL)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
39
libftx/libft/ft_lstmap.c
Normal file
39
libftx/libft/ft_lstmap.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/30 00:05:05 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/05 00:08:45 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *root;
|
||||
t_list *last;
|
||||
|
||||
if (f == NULL || del == NULL)
|
||||
return (NULL);
|
||||
root = ft_lstnew(f(lst->content));
|
||||
if (root == NULL)
|
||||
return (NULL);
|
||||
last = root;
|
||||
lst = lst->next;
|
||||
while (lst != NULL)
|
||||
{
|
||||
last->next = ft_lstnew(f(lst->content));
|
||||
if (last->next == NULL)
|
||||
{
|
||||
ft_lstclear(&root, del);
|
||||
return (NULL);
|
||||
}
|
||||
lst = lst->next;
|
||||
last = last->next;
|
||||
}
|
||||
return (root);
|
||||
}
|
25
libftx/libft/ft_lstnew.c
Normal file
25
libftx/libft/ft_lstnew.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 23:41:40 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 23:47:50 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = malloc(sizeof(t_list));
|
||||
if (new == NULL)
|
||||
return (NULL);
|
||||
new->next = NULL;
|
||||
new->content = content;
|
||||
return (new);
|
||||
}
|
26
libftx/libft/ft_lstsize.c
Normal file
26
libftx/libft/ft_lstsize.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/30 01:18:08 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/30 01:18:15 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
while (lst != NULL)
|
||||
{
|
||||
count++;
|
||||
lst = lst->next;
|
||||
}
|
||||
return (count);
|
||||
}
|
31
libftx/libft/ft_memchr.c
Normal file
31
libftx/libft/ft_memchr.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 13:40:09 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/27 13:59:03 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *tab;
|
||||
size_t i;
|
||||
unsigned char tofind;
|
||||
|
||||
tab = (unsigned char *) s;
|
||||
tofind = (unsigned char) c;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (tab[i] == tofind)
|
||||
return (tab + i);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
BIN
libftx/libft/ft_memchr.o
Normal file
BIN
libftx/libft/ft_memchr.o
Normal file
Binary file not shown.
29
libftx/libft/ft_memcmp.c
Normal file
29
libftx/libft/ft_memcmp.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 14:15:37 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/27 15:10:56 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *str1;
|
||||
unsigned char *str2;
|
||||
size_t i;
|
||||
|
||||
if (n == 0)
|
||||
return (0);
|
||||
str1 = (unsigned char *) s1;
|
||||
str2 = (unsigned char *) s2;
|
||||
i = 0;
|
||||
while (str1[i] == str2[i] && i < n - 1)
|
||||
i++;
|
||||
return (str1[i] - str2[i]);
|
||||
}
|
BIN
libftx/libft/ft_memcmp.o
Normal file
BIN
libftx/libft/ft_memcmp.o
Normal file
Binary file not shown.
32
libftx/libft/ft_memcpy.c
Normal file
32
libftx/libft/ft_memcpy.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 09:42:11 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 11:50:17 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *tab1;
|
||||
char *tab2;
|
||||
size_t i;
|
||||
|
||||
if (dest == NULL && src == NULL)
|
||||
return (dest);
|
||||
tab1 = dest;
|
||||
tab2 = (void *) src;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
tab1[i] = tab2[i];
|
||||
i++;
|
||||
}
|
||||
return (tab1);
|
||||
}
|
BIN
libftx/libft/ft_memcpy.o
Normal file
BIN
libftx/libft/ft_memcpy.o
Normal file
Binary file not shown.
37
libftx/libft/ft_memmove.c
Normal file
37
libftx/libft/ft_memmove.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 11:44:12 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/28 16:40:24 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
char *tab1;
|
||||
char *tab2;
|
||||
|
||||
if (dest == NULL && src == NULL)
|
||||
return (dest);
|
||||
tab1 = dest;
|
||||
tab2 = (void *) src;
|
||||
if (tab1 < tab2)
|
||||
ft_memcpy(dest, src, n);
|
||||
else
|
||||
{
|
||||
i = n;
|
||||
while (0 < i)
|
||||
{
|
||||
i--;
|
||||
tab1[i] = tab2[i];
|
||||
}
|
||||
}
|
||||
return (dest);
|
||||
}
|
BIN
libftx/libft/ft_memmove.o
Normal file
BIN
libftx/libft/ft_memmove.o
Normal file
Binary file not shown.
28
libftx/libft/ft_memset.c
Normal file
28
libftx/libft/ft_memset.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 09:29:51 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/27 09:48:23 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
char *tab;
|
||||
size_t i;
|
||||
|
||||
tab = s;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
tab[i] = c;
|
||||
i++;
|
||||
}
|
||||
return (s);
|
||||
}
|
BIN
libftx/libft/ft_memset.o
Normal file
BIN
libftx/libft/ft_memset.o
Normal file
Binary file not shown.
18
libftx/libft/ft_putchar_fd.c
Normal file
18
libftx/libft/ft_putchar_fd.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 22:23:35 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/05 18:54:54 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(int fd, char c)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
BIN
libftx/libft/ft_putchar_fd.o
Normal file
BIN
libftx/libft/ft_putchar_fd.o
Normal file
Binary file not shown.
21
libftx/libft/ft_putendl_fd.c
Normal file
21
libftx/libft/ft_putendl_fd.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 22:26:36 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 22:43:19 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
if (s == NULL)
|
||||
return ;
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
BIN
libftx/libft/ft_putendl_fd.o
Normal file
BIN
libftx/libft/ft_putendl_fd.o
Normal file
Binary file not shown.
34
libftx/libft/ft_putnbr_fd.c
Normal file
34
libftx/libft/ft_putnbr_fd.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 22:28:27 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 22:39:25 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
if (n == -2147483648)
|
||||
{
|
||||
ft_putnbr_fd(-2, fd);
|
||||
ft_putnbr_fd(147483648, fd);
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
ft_putnbr_fd(-n, fd);
|
||||
}
|
||||
else if (n > 9)
|
||||
{
|
||||
ft_putnbr_fd(n / 10, fd);
|
||||
ft_putnbr_fd(n % 10, fd);
|
||||
}
|
||||
else
|
||||
ft_putchar_fd(n + 48, fd);
|
||||
}
|
BIN
libftx/libft/ft_putnbr_fd.o
Normal file
BIN
libftx/libft/ft_putnbr_fd.o
Normal file
Binary file not shown.
21
libftx/libft/ft_putstr_fd.c
Normal file
21
libftx/libft/ft_putstr_fd.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 22:25:08 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 22:40:34 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
if (s == NULL)
|
||||
return ;
|
||||
while (*s)
|
||||
write(fd, s++, 1);
|
||||
}
|
BIN
libftx/libft/ft_putstr_fd.o
Normal file
BIN
libftx/libft/ft_putstr_fd.o
Normal file
Binary file not shown.
92
libftx/libft/ft_split.c
Normal file
92
libftx/libft/ft_split.c
Normal file
@ -0,0 +1,92 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/01/06 19:33:51 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_cancel(char **tab, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (tab != NULL)
|
||||
{
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
free(tab[i]);
|
||||
i++;
|
||||
}
|
||||
free(tab);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static size_t ft_seglen(const char *s, char c)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
len = 0;
|
||||
while (*s != 0)
|
||||
{
|
||||
while (*s == c && *s != 0)
|
||||
s++;
|
||||
if (*s != 0)
|
||||
len++;
|
||||
while (*s != c && *s != 0)
|
||||
s++;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)
|
||||
{
|
||||
size_t tab_index;
|
||||
size_t let_index;
|
||||
size_t start;
|
||||
|
||||
tab_index = 0;
|
||||
let_index = 0;
|
||||
start = 0;
|
||||
if (tab == NULL || s == NULL)
|
||||
return (NULL);
|
||||
while (tab_index < len)
|
||||
{
|
||||
while (s[let_index] == c && s[let_index] != 0)
|
||||
let_index++;
|
||||
start = let_index;
|
||||
while (s[let_index] != c && s[let_index] != 0)
|
||||
let_index++;
|
||||
tab[tab_index] = ft_substr(s, start, let_index - start);
|
||||
if (tab[tab_index] == NULL)
|
||||
return (ft_cancel(tab, tab_index));
|
||||
tab_index++;
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
|
||||
char **ft_split(const char *s, char c)
|
||||
{
|
||||
size_t len;
|
||||
char **tab;
|
||||
|
||||
if (s == NULL)
|
||||
return (NULL);
|
||||
len = ft_seglen(s, c);
|
||||
tab = malloc((len + 1) * sizeof(char *));
|
||||
if (tab == NULL)
|
||||
return (NULL);
|
||||
tab[len] = NULL;
|
||||
if (ft_segsplitter(tab, len, s, c) == NULL)
|
||||
return (NULL);
|
||||
return (tab);
|
||||
}
|
BIN
libftx/libft/ft_split.o
Normal file
BIN
libftx/libft/ft_split.o
Normal file
Binary file not shown.
24
libftx/libft/ft_strchr.c
Normal file
24
libftx/libft/ft_strchr.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/26 14:44:15 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/05 20:56:37 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
while (*s != (char) c)
|
||||
{
|
||||
if (*s == 0)
|
||||
return (NULL);
|
||||
s++;
|
||||
}
|
||||
return ((char *) s);
|
||||
}
|
BIN
libftx/libft/ft_strchr.o
Normal file
BIN
libftx/libft/ft_strchr.o
Normal file
Binary file not shown.
31
libftx/libft/ft_strdup.c
Normal file
31
libftx/libft/ft_strdup.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 16:00:49 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/04 23:24:11 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
char *out;
|
||||
size_t i;
|
||||
|
||||
out = ft_calloc((ft_strlen(s) + 1), sizeof(char));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
out[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
out[i] = 0;
|
||||
return (out);
|
||||
}
|
BIN
libftx/libft/ft_strdup.o
Normal file
BIN
libftx/libft/ft_strdup.o
Normal file
Binary file not shown.
27
libftx/libft/ft_striteri.c
Normal file
27
libftx/libft/ft_striteri.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 22:21:01 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/10/04 15:01:00 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (s == NULL)
|
||||
return ;
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, s + i);
|
||||
i++;
|
||||
}
|
||||
}
|
BIN
libftx/libft/ft_striteri.o
Normal file
BIN
libftx/libft/ft_striteri.o
Normal file
Binary file not shown.
38
libftx/libft/ft_strjoin.c
Normal file
38
libftx/libft/ft_strjoin.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/29 11:20:27 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/29 11:30:50 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(const char *s1, const char *s2)
|
||||
{
|
||||
char *out;
|
||||
ssize_t i;
|
||||
ssize_t j;
|
||||
size_t len_s1;
|
||||
size_t len_s2;
|
||||
|
||||
if (s1 == NULL || s2 == NULL)
|
||||
return (NULL);
|
||||
len_s1 = ft_strlen(s1);
|
||||
len_s2 = ft_strlen(s2);
|
||||
out = malloc(sizeof(char) * (len_s1 + len_s2 + 1));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i < (ssize_t) len_s1)
|
||||
out[i] = s1[i];
|
||||
j = -1;
|
||||
while (++j < (ssize_t) len_s2)
|
||||
out[j + i] = s2[j];
|
||||
out[i + j] = 0;
|
||||
return (out);
|
||||
}
|
BIN
libftx/libft/ft_strjoin.o
Normal file
BIN
libftx/libft/ft_strjoin.o
Normal file
Binary file not shown.
25
libftx/libft/ft_strlcat.c
Normal file
25
libftx/libft/ft_strlcat.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 17:02:13 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/28 17:11:29 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t len_dest;
|
||||
|
||||
if (size == 0)
|
||||
return (ft_strlen(src));
|
||||
len_dest = ft_strlen(dest);
|
||||
if (len_dest >= size)
|
||||
return (ft_strlen(src) + (size));
|
||||
return (len_dest + ft_strlcpy(dest + len_dest, src, size - len_dest));
|
||||
}
|
BIN
libftx/libft/ft_strlcat.o
Normal file
BIN
libftx/libft/ft_strlcat.o
Normal file
Binary file not shown.
28
libftx/libft/ft_strlcpy.c
Normal file
28
libftx/libft/ft_strlcpy.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 16:24:15 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/09/28 17:23:27 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i + 1 < size && src[i])
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
if (size)
|
||||
dst[i] = 0;
|
||||
return (ft_strlen(src));
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user