This is my custom libft that I use in 42 projects!
It contains all of the functions in the mandatory and bonus parts of the libft project, as well as my ft_printf/ft_fprintf and my implementation of get_next_line. It also now has a (kind of) garbage collector!
- unistd: Unix standard functions; includes system calls like "write".
- stdlib: Standard C library.
- stdio: Standard I/O.
- stdarg: Contains useful argument utils such as "va_arg".
- stdint: Useful number related macros and typedefs such as "uint32".
- stdbool: Boolean definition instead of using an integer.
- limits: Useful defines related to numeric limits such as "INT_MIN"
- fcntl: File manipulation such as "open".
- math: The C math library with constant like "PI" and tons of operations.
!: Functions with this indicator allocate memory but do not free it for you, therefore they are integrated with the garbage collector.
- Memory manipulation:
- ft_bzero: Zeros out specified memory
- ft_memchr: Locates and returns the adress of the character
cin strings - ft_memcmp: Returns the difference in ascii between two given points in memory
- ft_memcpy: Copies the value of
srcinto the adress ofdst - ft_memmove: Copies
lenbytes fromsrctodst - ft_memset: Like ft_bzero, but sets specified range in memory to value
c - ft_calloc: Allocates memory for an array of
countitems each ofsizebytes
- String manipulation:
- ft_strchr: Returns a string poiting to the first appereace of the character
cin strings - ft_strrchr: Reversed version of ft_strchr
- ft_strnstr: Returns
haystackpointing to the first occurance ofneedlein it up to the lengthlen - ft_substr !: Copies a specified substring from a string into a new one with ft_strdup
- ft_strtrim !: Trims
setstring off the start and end of strings1 - ft_strcpy: Compies the contents of string
s1and replacess2with it, then returnss2 - ft_strlcpy: Returns the resultant length of copying
srctodst, truncated bydstsize - ft_strcat: Resturns the resultant concatenation of
dstwithsrc, adding on itdst - ft_strlcat: Returns the resultant length of concatenating
dstwithsrc, truncated bydstsize - ft_strdup !: Dupclicates a string by allocating memory to a new one and copying to said address
- ft_strjoin !: Uses concatenation to add a string onto the end of another
- ft_strncmp: Returns the differnce in ascii between the first differing charater of
s1ands2, up ton - ft_strlen: Returns the length of a given string
- ft_split !: Splits string
strby delimiter characterc(not including) and returns an array of the split strings - ft_striteri: Applies a function
fpassed as a parameter to strings - ft_strmapi: Identical to ft_striteri but returns the string after the function is applied to it
- ft_strchr: Returns a string poiting to the first appereace of the character
- Conversion functions:
- ft_atoi: Converts a string to its integer form, ignoring invalid input
- ft_atof: Converts a string to its float form, ignoring invalid input
- ft_itoa: Convers an integer to its string form, returning
0if input is invalid - ft_tolower: Converts an alphabetic character to its lower-case form
- ft_toupper: Converts an alphabetic character to its upper-case form
- Character booleans:
- ft_isalnum: Returns true if the given character is alphanumeric
- ft_isalpha: Returns true if the given character is alphanbetical
- ft_isascii: Returns true if the given character is valid ascii
- ft_isdigit: Returns true if the given character is a digit
- ft_isprint: Returns true if the given character is a printable character
- Linked list utils:
- ft_lstnew: Creates a new linked list
- ft_lstsize: Returns the size of a linked list
- ft_lstclear: Clears a linked list fully
- ft_lstdelone: Deletes a node from a linked list
- ft_lstadd_front: Adds a node to the front of a linked list
- ft_lstadd_back: Adds a node to the back of a linked list
- ft_lstiter: Applies a function
fpassed as a parameter to all nodes in a linked list - ft_lstmap: Creates a new linked list by applying a function
fto each node's content of an existing linked list. If the allocation of a new node fails, it deletes the content and clears the new list.
- Writing functions:
- ft_putchar_fd: Writes a character
ctofd - ft_putstr_fd: Writes a string
strtofd - ft_putendl_fd: Writes a character
ctofd, terminating with a newline character - ft_putnbr_fd: Writes a number
nbrtofd
- ft_putchar_fd: Writes a character
- Sub-Project functions:
- ft_fprintf: Custom reimplementation of fprintf made from my ft_printf project, prints formated string to
fd - get_next_line !: My get_next_line project (very improvable), returns the next line read from
fd - gc_malloc: Calls malloc and adds a node with a reference to the allocated pointer to the garbage collector list
- gc_free: Frees the specified pointer and removes its node from the garbage collector list
- gc_collect: Frees all remaining allocations in the garbage collector list
- ft_fprintf: Custom reimplementation of fprintf made from my ft_printf project, prints formated string to
This libft constains a garbage collection system which replaces and malloc and free functions and uses a linked list to keep track of pointers to allocated memory. The gc_collect() function then frees everything off. The list functions like a stack, with a first-in-last-out logic.
All structs related to linked lists are also included so that they can easily be created. Will add more linked list related utils in the future!