Save
This commit is contained in:
parent
91730ee04c
commit
d21e3a9025
23
Makefile
23
Makefile
|
@ -33,31 +33,32 @@ _SRC += ft_strnstr.c
|
|||
_SRC += ft_strrchr.c
|
||||
_SRC += ft_tolower.c
|
||||
_SRC += ft_toupper.c
|
||||
# _SRC += ft_putchar_fd.c
|
||||
# _SRC += ft_putendl_fd.c
|
||||
# _SRC += ft_putnbr_fd.c
|
||||
# _SRC += ft_putstr_fd.c
|
||||
_SRC += ft_putchar_fd.c
|
||||
_SRC += ft_putendl_fd.c
|
||||
_SRC += ft_putnbr_fd.c
|
||||
_SRC += ft_putstr_fd.c
|
||||
|
||||
# _SRC += ft_itoa.c
|
||||
_SRC += ft_itoa.c
|
||||
_SRC += ft_strtrim.c
|
||||
_SRC += ft_substr.c
|
||||
_SRC += ft_strjoin.c
|
||||
_SRC += ft_split.c
|
||||
# _SRC += ft_striteri.c
|
||||
# _SRC += ft_strmapi.c
|
||||
_SRC += ft_striteri.c
|
||||
_SRC += ft_strmapi.c
|
||||
|
||||
_SRC += ft_lstnew.c
|
||||
_SRC += ft_lstadd_front.c
|
||||
# _SRC += ft_lstadd_back.c
|
||||
# _SRC += ft_lstadd_front.c
|
||||
# _SRC += ft_lstclear
|
||||
# _SRC += ft_lstdelone.c
|
||||
# _SRC += ft_lstiter.c
|
||||
# _SRC += ft_lstlast.c
|
||||
# _SRC += ft_lstmap.c
|
||||
# _SRC += ft_lstnew.c
|
||||
# _SRC += ft_lstsize.c
|
||||
|
||||
_SRC += ft_char_in_charset.c
|
||||
_SRC += ft_isspace.c
|
||||
_SRC += ft_abs.c
|
||||
|
||||
unexport _DEPS
|
||||
_DEPS += libft.h
|
||||
|
@ -68,10 +69,6 @@ OBJ = $(addprefix $(OBJDIR)/,$(_OBJ))
|
|||
SRC = $(addprefix $(SRCDIR)/,$(_SRC))
|
||||
DEPS = $(addprefix $(INCDIR)/,$(_DEPS))
|
||||
|
||||
so:
|
||||
$(CC) -nostartfiles -fPIC $(CFLAGS) $(SRC)
|
||||
gcc -nostartfiles -shared -o libft.so $(OBJ)
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_abs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/03 11:52:45 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/03 11:52:45 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
unsigned int ft_abs(int n)
|
||||
{
|
||||
if (n > 0)
|
||||
return (n);
|
||||
else
|
||||
return (-(unsigned int) n);
|
||||
}
|
BIN
ft_bzero.o
BIN
ft_bzero.o
Binary file not shown.
BIN
ft_calloc.o
BIN
ft_calloc.o
Binary file not shown.
BIN
ft_isalnum.o
BIN
ft_isalnum.o
Binary file not shown.
BIN
ft_isalpha.o
BIN
ft_isalpha.o
Binary file not shown.
BIN
ft_isascii.o
BIN
ft_isascii.o
Binary file not shown.
BIN
ft_isdigit.o
BIN
ft_isdigit.o
Binary file not shown.
BIN
ft_isprint.o
BIN
ft_isprint.o
Binary file not shown.
BIN
ft_isspace.o
BIN
ft_isspace.o
Binary file not shown.
43
ft_itoa.c
43
ft_itoa.c
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/03 11:32:41 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/03 11:32:41 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *str;
|
||||
size_t n_len;
|
||||
unsigned int n_cpy;
|
||||
int is_neg;
|
||||
|
||||
is_neg = n < 0;
|
||||
n_len = 0;
|
||||
n_cpy = ft_abs(n) + !n;
|
||||
while (n_cpy * ++n_len != 0)
|
||||
n_cpy /= 10;
|
||||
--n_len;
|
||||
str = malloc(sizeof(*str) * (n_len + is_neg + 1));
|
||||
if (!str)
|
||||
return (0);
|
||||
str += n_len + is_neg;
|
||||
n_cpy = ft_abs(n);
|
||||
*str-- = 0;
|
||||
while (n_len--)
|
||||
{
|
||||
*str-- = n_cpy % 10 + '0';
|
||||
n_cpy /= 10;
|
||||
}
|
||||
if (is_neg)
|
||||
*str-- = '-';
|
||||
return (++str);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/14 11:57:15 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/14 11:57:15 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (lst)
|
||||
{
|
||||
if (*lst)
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
}
|
26
ft_lstnew.c
26
ft_lstnew.c
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:55:31 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:55:31 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = malloc(sizeof(*new));
|
||||
if (!new)
|
||||
return (0);
|
||||
new->content = content;
|
||||
new->next = 0;
|
||||
return (new);
|
||||
}
|
BIN
ft_memchr.o
BIN
ft_memchr.o
Binary file not shown.
BIN
ft_memcmp.o
BIN
ft_memcmp.o
Binary file not shown.
BIN
ft_memcpy.o
BIN
ft_memcpy.o
Binary file not shown.
BIN
ft_memmove.o
BIN
ft_memmove.o
Binary file not shown.
BIN
ft_memset.o
BIN
ft_memset.o
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:24:36 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:24:37 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:27:38 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:28:47 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:29:25 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:29:26 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <limits.h>
|
||||
|
||||
void ft_putnbr_fd(int nb, int fd)
|
||||
{
|
||||
if (nb > 9)
|
||||
{
|
||||
ft_putnbr_fd(nb / 10, fd);
|
||||
ft_putchar_fd(nb % 10 + '0', fd);
|
||||
}
|
||||
else if (nb == INT_MIN)
|
||||
{
|
||||
ft_putnbr_fd(nb / 10, fd);
|
||||
ft_putnbr_fd(-(nb % 10), fd);
|
||||
}
|
||||
else if (nb < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
ft_putnbr_fd(-nb, fd);
|
||||
}
|
||||
else
|
||||
ft_putchar_fd(nb % 10 + '0', fd);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:26:11 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:26:11 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
while (*s)
|
||||
ft_putchar_fd(*s++, fd);
|
||||
}
|
|
@ -22,6 +22,8 @@ static size_t split_arr_len(char const *s, char c)
|
|||
{
|
||||
while (*s == c)
|
||||
++s;
|
||||
if (!*s)
|
||||
return (len);
|
||||
++len;
|
||||
while (*s != c && *s)
|
||||
++s;
|
||||
|
@ -50,7 +52,7 @@ char **ft_split(char const *s, char c)
|
|||
char const *start;
|
||||
|
||||
arr_len = split_arr_len(s, c);
|
||||
arr = malloc(sizeof(char *) * (arr_len + 1));
|
||||
arr = malloc(sizeof(*arr) * (arr_len + 1));
|
||||
if (!arr)
|
||||
return (0);
|
||||
idx = 0;
|
||||
|
@ -58,10 +60,12 @@ char **ft_split(char const *s, char c)
|
|||
{
|
||||
while (*s == c)
|
||||
++s;
|
||||
if (!*s)
|
||||
break ;
|
||||
start = s;
|
||||
while (*s != c && *s)
|
||||
++s;
|
||||
arr[idx] = malloc(sizeof(char) * (s - start + 1));
|
||||
arr[idx] = malloc(sizeof(**arr) * (s - start + 1));
|
||||
if (!save_strlcpy(arr, ++idx, start, s - start + 1))
|
||||
return (0);
|
||||
}
|
||||
|
|
BIN
ft_strchr.o
BIN
ft_strchr.o
Binary file not shown.
|
@ -19,7 +19,7 @@ char *ft_strdup(char const *s)
|
|||
size_t len;
|
||||
|
||||
len = ft_strlen(s);
|
||||
s2 = malloc(sizeof(char) * (len + 1));
|
||||
s2 = malloc(sizeof(*s2) * (len + 1));
|
||||
if (!s2)
|
||||
return (0);
|
||||
ft_strlcpy(s2, (char *) s, len + 1);
|
||||
|
|
BIN
ft_strdup.o
BIN
ft_strdup.o
Binary file not shown.
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/09 14:47:33 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/09 14:47:34 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = -1;
|
||||
while (s[++idx])
|
||||
(f)(idx, &s[idx]);
|
||||
}
|
|
@ -18,7 +18,7 @@ char *ft_strjoin(char const *s1, char const *s2)
|
|||
char *joined_str;
|
||||
|
||||
total_len = ft_strlen(s1) + ft_strlen(s2);
|
||||
joined_str = ft_calloc(total_len + 1, sizeof(char));
|
||||
joined_str = ft_calloc(total_len + 1, sizeof(*joined_str));
|
||||
if (!joined_str)
|
||||
return (0);
|
||||
ft_strlcat(joined_str, s1, total_len + 1);
|
||||
|
|
BIN
ft_strlcat.o
BIN
ft_strlcat.o
Binary file not shown.
BIN
ft_strlcpy.o
BIN
ft_strlcpy.o
Binary file not shown.
BIN
ft_strlen.o
BIN
ft_strlen.o
Binary file not shown.
29
ft_strmapi.c
29
ft_strmapi.c
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/03 12:41:34 by tosuman #+# #+# */
|
||||
/* Updated: 2023/06/03 12:41:34 by tosuman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strmapi(char const *s, char (f)(unsigned int, char))
|
||||
{
|
||||
char *str;
|
||||
int idx;
|
||||
|
||||
str = malloc(sizeof(*str) * (ft_strlen(s) + 1));
|
||||
if (!str)
|
||||
return (0);
|
||||
idx = -1;
|
||||
while (s[++idx])
|
||||
str[idx] = (f)(idx, s[idx]);
|
||||
str[idx] = 0;
|
||||
return (str);
|
||||
}
|
BIN
ft_strncmp.o
BIN
ft_strncmp.o
Binary file not shown.
BIN
ft_strnstr.o
BIN
ft_strnstr.o
Binary file not shown.
BIN
ft_strrchr.o
BIN
ft_strrchr.o
Binary file not shown.
|
@ -40,7 +40,7 @@ char *ft_strtrim(char const *s1, char const *set)
|
|||
char *trimmed_str;
|
||||
|
||||
trimmed_len = len_after_trim(s1, set);
|
||||
trimmed_str = malloc(sizeof(char) * (trimmed_len + 1));
|
||||
trimmed_str = malloc(sizeof(*trimmed_str) * (trimmed_len + 1));
|
||||
if (!trimmed_str)
|
||||
return (0);
|
||||
while (ft_char_in_charset(*s1, set))
|
||||
|
|
|
@ -25,7 +25,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
|
|||
;
|
||||
if (!s[idx])
|
||||
{
|
||||
empty = ft_calloc(1, sizeof(char));
|
||||
empty = ft_calloc(1, sizeof(*empty));
|
||||
if (!empty)
|
||||
return (0);
|
||||
return (empty);
|
||||
|
@ -33,7 +33,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
|
|||
real_len = 0;
|
||||
while (++real_len <= len && s[idx + real_len - 1])
|
||||
;
|
||||
substr = malloc(sizeof(char) * real_len);
|
||||
substr = malloc(sizeof(*substr) * real_len);
|
||||
if (!substr)
|
||||
return (0);
|
||||
ft_strlcpy(substr, s + idx, real_len);
|
||||
|
|
BIN
ft_substr.o
BIN
ft_substr.o
Binary file not shown.
BIN
ft_tolower.o
BIN
ft_tolower.o
Binary file not shown.
BIN
ft_toupper.o
BIN
ft_toupper.o
Binary file not shown.
72
libft.h
72
libft.h
|
@ -12,42 +12,54 @@
|
|||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
# define UINT unsigned int
|
||||
# include <stddef.h>
|
||||
|
||||
int ft_atoi(char const *nptr);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_isspace(int c);
|
||||
void *ft_memchr(void const *s, int c, size_t n);
|
||||
int ft_memcmp(void const *s1, void const *s2, size_t n);
|
||||
void *ft_memcpy(void *dest, void const *src, size_t n);
|
||||
void *ft_memmove(void *dest, void const *src, size_t n);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
char *ft_strchr(char const *s, int c);
|
||||
char *ft_strdup(char const *s);
|
||||
size_t ft_strlcat(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlcpy(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlen(char const *s);
|
||||
int ft_strncmp(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strnstr(char const *big, char const *little, size_t len);
|
||||
char *ft_strrchr(char const *s, int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_toupper(int c);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
int ft_char_in_charset(char c, char const *charset);
|
||||
char **ft_split(char const *s, char c);
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
void *ft_memmove(void *dest, void const *src, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
void *ft_memset(void *s, int c, unsigned long n);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(void const *s1, void const *s2, size_t n);
|
||||
void *ft_memcpy(void *dest, void const *src, size_t n);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isspace(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
char *ft_strnstr(char const *big, char const *little, size_t len);
|
||||
char *ft_strchr(char const *s, int c);
|
||||
char *ft_strrchr(char const *s, int c);
|
||||
char *ft_strdup(char const *s);
|
||||
int ft_strncmp(char const *s1, char const *s2, size_t n);
|
||||
size_t ft_strlen(char const *s);
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
size_t ft_strlcat(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlcat(char *dst, char const *src, size_t size);
|
||||
size_t ft_strlcpy(char *dst, char const *src, size_t size);
|
||||
char *ft_strmapi(char const *s, char (f)(unsigned int, char));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
char *ft_itoa(int n);
|
||||
int ft_atoi(char const *nptr);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int nb, int fd);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
int ft_char_in_charset(char c, char const *charset);
|
||||
UINT ft_abs(int n);
|
||||
t_list *ft_lstnew(void *content);
|
||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue