Libft
 
Loading...
Searching...
No Matches
libft.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* libft.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: ppontet <ppontet@student.42lyon.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/11/04 13:25:12 by ppontet #+# #+# */
9/* Updated: 2025/06/13 23:55:17 by ppontet ### ########lyon.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef LIBFT_H
14# define LIBFT_H
15
16# include <stddef.h>
17# include <unistd.h>
18
24# ifndef FX_VA
25# define FX_VA 0
26# endif
27
32typedef enum e_bool
33{
34 FALSE = 0,
35 TRUE = 1
37
41typedef struct s_list
42{
43 void *content;
44 struct s_list *next;
46
52int ft_atoi(const char *nptr);
53int ft_atoi_base(char *str, char *base);
54char *ft_itoa(int n);
56
62int ft_isalpha(int character);
63int ft_isdigit(int character);
64int ft_isalnum(int character);
65int ft_isascii(int character);
66int ft_isprint(int character);
67int ft_toupper(int character);
68int ft_tolower(int character);
69int ft_isspace(int character);
70int ft_iswhitespace(int character);
72
78size_t ft_strlen(const char *the_string);
79size_t ft_strlen_char(const char *the_string, int character);
80size_t ft_strlcpy(char *dst, const char *src, size_t size);
81size_t ft_strlcat(char *dst, const char *src, size_t size);
82char *ft_strchr(const char *string, int searched_char);
83char *ft_strrchr(const char *string, int searched_char);
84int ft_strncmp(const char *first, const char *second, size_t length);
85const char *ft_strnstr(const char *big, const char *little, size_t len);
86char *ft_strdup(const char *source);
87char *ft_strndup(const char *source, size_t len);
88char *ft_substr(char const *src, unsigned int start, size_t len);
89char *ft_strjoin(char const *s1, char const *s2);
90char *ft_strjoins(char **str);
91# if (FX_VA == 1)
92
93char *ft_strjoins_va(char const *str, ...);
94# endif
95
96char *ft_strtrim(char const *s, char const *set);
97char **ft_split(char const *s, char c);
98char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
99void ft_striteri(char *s, void (*f)(unsigned int, char *));
101
107void ft_rev_int(int *tab, size_t size);
109
115void ft_bzero(void *s, size_t n);
116void *ft_memcpy(void *destination, const void *source, size_t size);
117void *ft_memset(void *pointer, int value, size_t count);
118void *ft_memmove(void *destination, const void *source, size_t size);
119const void *ft_memchr(const void *memory_block, int searched_char,
120 size_t size);
121int ft_memcmp(const void *src, const void *set, size_t size);
122void *ft_calloc(size_t element_count, size_t element_size);
124
130void ft_swap_int(int *a, int *b);
131void ft_swap_char(char *a, char *b);
132void ft_swap_str(char **a, char **b);
133void ft_swap_mem(void **a, void **b);
134// SPECIAL SWAPS
135void ft_swap_int_no_temp(int *a, int *b);
136void ft_swap_char_no_temp(char *a, char *b);
137// void ft_swap_str_no_temp(char **a, char **b);
138// void ft_swap_mem_no_temp(void **a, void **b);
140
146ssize_t ft_putchar_fd(const char c, int fd);
147ssize_t ft_putstr_fd(const char *s, int fd);
148ssize_t ft_putnstr_fd(const char *s, size_t len, int fd);
149ssize_t ft_putendl_fd(const char *s, int fd);
150ssize_t ft_putnendl_fd(const char *s, size_t len, int fd);
151ssize_t ft_putnbr_fd(long long n, int fd);
152
153ssize_t ft_putnbr_bin(int nbr);
154// void ft_putnbr_poneyvif(int nbr);
155ssize_t ft_putnbr_oct(int nbr);
156ssize_t ft_putnbr_hex(int nbr, char height);
157ssize_t ft_putnbr_hex_fd(unsigned int nbr, char height, int fd);
158ssize_t ft_putptr_fd(unsigned long nbr, int fd);
159ssize_t ft_putnbr_base(int nbr, const char *base);
160size_t ft_check_base_atoi(const char *base);
161size_t ft_check_base_putnbr(const char *base);
162ssize_t ft_putpointer_fd(const void *ptr);
164
170t_list *ft_lstnew(void *content);
171void ft_lstadd_front(t_list **lst, t_list *new);
172int ft_lstsize(t_list *lst);
174void ft_lstadd_back(t_list **lst, t_list *new);
175void ft_lstdelone(t_list *lst, void (*del)(void *));
176void ft_lstclear(t_list **lst, void (*del)(void *));
177void ft_lstiter(t_list *lst, void (*f)(void *));
178t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
179void ft_swap_nodes(t_list **start, t_list *lst1, t_list *lst2);
181
187void ft_frees(void **ptr);
188# if (FX_VA == 1)
189
190void ft_frees_va(void *ptr, ...);
191# endif
192
194
195#endif
void ft_frees_va(void *ptr,...)
Frees multiple pointers using va_list.
Definition ft_frees_va.c:24
char * ft_strjoins_va(char const *str,...)
Allocates a new string, and returns the result of a concatenation of str and all the arguments last a...
Definition ft_strjoins_va.c:29
char * ft_itoa(int n)
Return a string representing the integer 'n' received as argument.
Definition ft_itoa.c:24
int ft_atoi_base(char *str, char *base)
Atoi with a particular base.
Definition ft_atoi_base.c:25
int ft_atoi(const char *nptr)
Convert string to int, and handle number.
Definition ft_atoi.c:21
int ft_iswhitespace(int character)
Alternative name for ft_isspace.
Definition ft_isspace.c:35
int ft_isdigit(int character)
Check if arg is a digit.
Definition ft_isdigit.c:22
int ft_isascii(int character)
Check if arg is in ascii table.
Definition ft_isascii.c:22
int ft_toupper(int character)
Transform minuscules into majuscules.
Definition ft_toupper.c:22
int ft_tolower(int character)
Transform majuscules into minuscules.
Definition ft_tolower.c:22
int ft_isspace(int character)
Check if arg is a whitespace.
Definition ft_isspace.c:22
int ft_isalpha(int character)
Check if arg is a char alphabetic.
Definition ft_isalpha.c:22
int ft_isalnum(int character)
Check if arg is a char or a digit (alphanumeric)
Definition ft_isalnum.c:22
int ft_isprint(int character)
Check if arg is in ascii table and printable.
Definition ft_isprint.c:22
void ft_frees(void **ptr)
Frees multiple pointers.
Definition ft_frees.c:21
void ft_lstadd_front(t_list **lst, t_list *new)
Adds the element ’new’ at the start of the list.
Definition ft_lstadd_front_bonus.c:21
void ft_lstiter(t_list *lst, void(*f)(void *))
Iterate on the linked list 'lst' and apply the function 'f' on the content of each element.
Definition ft_lstiter_bonus.c:22
void ft_swap_nodes(t_list **start, t_list *lst1, t_list *lst2)
Swap two nodes in a linked list (swap nodes, not content)
Definition ft_swap_nodes.c:26
void ft_lstadd_back(t_list **lst, t_list *new)
Adds the element ’new’ at the end of the list.
Definition ft_lstadd_back_bonus.c:21
void ft_lstclear(t_list **lst, void(*del)(void *))
Deletes and free the memory of the element passed as a parameter, and all the elements that follow,...
Definition ft_lstclear_bonus.c:24
t_list * ft_lstmap(t_list *lst, void *(*f)(void *), void(*del)(void *))
Iterated on the linked list 'list' and apply the function 'f' on the content of each element....
Definition ft_lstmap_bonus.c:32
t_list * ft_lstnew(void *content)
Allocate (with malloc(3)) and return a new element. The variable member 'content' is initialized with...
Definition ft_lstnew_bonus.c:25
int ft_lstsize(t_list *lst)
Count the number of elements in a list.
Definition ft_lstsize_bonus.c:21
void ft_lstdelone(t_list *lst, void(*del)(void *))
Free the memory of the element passed as a parameter using the function 'del' and free(3)....
Definition ft_lstdelone_bonus.c:24
t_list * ft_lstlast(t_list *lst)
Returns the last element of the list.
Definition ft_lstlast_bonus.c:21
void * ft_calloc(size_t element_count, size_t element_size)
Allocates a new memory zone, and set all bits to zero.
Definition ft_calloc.c:25
void ft_bzero(void *s, size_t n)
Set at 0, the n first bytes at the pointer adress.
Definition ft_bzero.c:23
void * ft_memset(void *pointer, int value, size_t count)
Set a memory zone with a value, count times.
Definition ft_memset.c:26
void * ft_memcpy(void *destination, const void *source, size_t size)
Set a memory zone with a value, count times.
Definition ft_memcpy.c:25
void * ft_memmove(void *destination, const void *source, size_t size)
Moves the memory blocks avoiding overlapping, until size blocks.
Definition ft_memmove.c:25
int ft_memcmp(const void *src, const void *set, size_t size)
Compares the first size bytes of the memory areas src and set.
Definition ft_memcmp.c:25
const void * ft_memchr(const void *memory_block, int searched_char, size_t size)
Research the first occurence of a value typed int, but interpreted as a char in a memory block.
Definition ft_memchr.c:28
ssize_t ft_putstr_fd(const char *s, int fd)
Print the string 's' on the file descriptor.
Definition ft_putstr_fd.c:23
ssize_t ft_putnbr_oct(int nbr)
Putnbr for octal.
Definition ft_putnbr_base.c:64
ssize_t ft_putnstr_fd(const char *s, size_t len, int fd)
Print the string 's' on the file descriptor until a given size or the length of s if len is greater.
Definition ft_putstr_fd.c:39
ssize_t ft_putendl_fd(const char *s, int fd)
Print the string 's' on the file descriptor, followed by a newline.
Definition ft_putendl_fd.c:23
ssize_t ft_putnendl_fd(const char *s, size_t len, int fd)
Print the string 's' on the file descriptor, followed by a newline until a given size or the length o...
Definition ft_putendl_fd.c:37
ssize_t ft_putnbr_hex_fd(unsigned int nbr, char height, int fd)
Putnbr for hex or HEX.
Definition ft_putnbr_base_hex.c:55
ssize_t ft_putnbr_hex(int nbr, char height)
Putnbr for hex or HEX.
Definition ft_putnbr_base.c:75
ssize_t ft_putptr_fd(unsigned long nbr, int fd)
Print pointer adress.
Definition ft_putnbr_base_hex.c:102
ssize_t ft_putchar_fd(const char c, int fd)
Print the character 'c' on the file descriptor.
Definition ft_putchar_fd.c:24
size_t ft_check_base_putnbr(const char *base)
Check if base is valid for putnbr_base.
Definition ft_convert_base.c:51
ssize_t ft_putnbr_base(int nbr, const char *base)
Putnbr with a particular base.
Definition ft_putnbr_base.c:23
ssize_t ft_putpointer_fd(const void *ptr)
Print pointer adress.
Definition ft_putpointer_fd.c:21
ssize_t ft_putnbr_bin(int nbr)
Putnbr for binary.
Definition ft_putnbr_base.c:54
size_t ft_check_base_atoi(const char *base)
Check if base is valid for atoi_base.
Definition ft_convert_base.c:21
ssize_t ft_putnbr_fd(long long n, int fd)
Write the int 'n' on the given file descriptor.
Definition ft_putnbr_fd.c:25
void ft_rev_int(int *tab, size_t size)
Reverse an array of ints.
Definition ft_rev_int.c:23
char * ft_strjoins(char **str)
Allocates a new string, and returns the result of a concatenation of all the strings from the array l...
Definition ft_strjoins.c:27
const char * ft_strnstr(const char *big, const char *little, size_t len)
Search a substring in a bigger string, up to len position in string.
Definition ft_strnstr.c:25
size_t ft_strlcat(char *dst, const char *src, size_t size)
Concatenate src into dst, up to size bytes.
Definition ft_strlcat.c:24
size_t ft_strlen_char(const char *the_string, int character)
Number of occurrence of character in the string.
Definition ft_strlen.c:43
char * ft_strmapi(char const *s, char(*f)(unsigned int, char))
Apply the function ’f’ to each character of the string ’s’, passing its index as first argument and t...
Definition ft_strmapi.c:26
size_t ft_strlen(const char *the_string)
Len of string without '\0'.
Definition ft_strlen.c:24
char * ft_strrchr(const char *string, int searched_char)
Find last occurrence of searched_char.
Definition ft_strrchr.c:24
char * ft_strjoin(char const *s1, char const *s2)
Allocates a new string, and returns the result of a concatenation of s1 and s2.
Definition ft_strjoin.c:24
char * ft_strndup(const char *source, size_t len)
Create a copy of source into a new pointer of size len NEEDS to be freed.
Definition ft_strdup.c:53
size_t ft_strlcpy(char *dst, const char *src, size_t size)
char ** ft_split(char const *s, char c)
Allocates with a malloc and returns an array of strings obtained by separating ’s’ using the characte...
Definition ft_split.c:29
char * ft_strchr(const char *string, int searched_char)
Find first occurrence of searched_char.
Definition ft_strchr.c:24
int ft_strncmp(const char *first, const char *second, size_t length)
Find differences between first and second.
Definition ft_strncmp.c:26
char * ft_strdup(const char *source)
Create a copy of source into a new pointer NEEDS to be freed.
Definition ft_strdup.c:24
char * ft_substr(char const *src, unsigned int start, size_t len)
Create a copy of source into a new pointer, at start, of size len NEEDS to be freed.
Definition ft_substr.c:26
void ft_striteri(char *s, void(*f)(unsigned int, char *))
Iterate the function f on string s.
Definition ft_striteri.c:21
char * ft_strtrim(char const *s, char const *set)
Deletes all characters that exist in s and set, if they are at the beginning of the string or at the ...
Definition ft_strtrim.c:26
void ft_swap_char(char *a, char *b)
Swap 2 char values.
Definition ft_swap.c:39
void ft_swap_char_no_temp(char *a, char *b)
Works similarly as ft_swap_char but doens't use temporary variable SHOULD NOT BE USED IF a and b poin...
Definition ft_swap_no_temp.c:37
void ft_swap_str(char **a, char **b)
Swap 2 string addresses.
Definition ft_swap.c:54
void ft_swap_int(int *a, int *b)
Swap 2 int values.
Definition ft_swap.c:24
void ft_swap_int_no_temp(int *a, int *b)
Works similarly as ft_swap_int but doens't use temporary variable SHOULD NOT BE USED IF a and b point...
Definition ft_swap_no_temp.c:23
void ft_swap_mem(void **a, void **b)
Swap 2 memory adresses.
Definition ft_swap.c:69
e_bool
Basic type to mimic stdbool.
Definition libft.h:33
@ FALSE
Definition libft.h:34
@ TRUE
Definition libft.h:35
enum e_bool t_bool
Basic type to mimic stdbool.
struct s_list t_list
Structure for linked list.
Structure for linked list.
Definition libft.h:42
struct s_list * next
Definition libft.h:44
void * content
Definition libft.h:43