This project has been created as part of the 42 curriculum by zleullie.
My very first library, with general purpose functions for writing C programs.
Libft is a set of general purpose functions that help with memory handling, string manipulation, creating and editing linked lists, and much more. They were created based on code that I wrote during the Piscine, with some extras. I have organized some functions in the same file as others, because their funcitonality was similar.
To compile this library, run:
$ makeTo compile cleanly (removing leftover binaries):
$ make reTo clean the intermediary objects:
$ make cleanTo clean all binaries:
$ make fcleanTo develop these functions, I have read source code from Glibc, Musl, FreeBSD's libc, and Apple's Darwin kernel's libc. I have written the functions myself, only analyzing the way they work to assist in the understanding of the logic required.
AI was used to develop a testing application, but not to develop any functions in this project.
AI was also used to assist in the writing of the list of functions and their description, in the section below.
int ft_isalnum(int c);- Checks for an alphanumeric character.int ft_isalpha(int c);- Checks for an alphabetic character.int ft_isdigit(int c);- Checks for a digit (0 through 9).int ft_isprint(int c);- Checks for any printable character.int ft_isascii(int c);- Checks whethercis a 7-bit unsigned char value that fits into the ASCII character set.int ft_toupper(int c);- Converts a lower-case letter to the corresponding upper-case letter.int ft_tolower(int c);- Converts an upper-case letter to the corresponding lower-case letter.
size_t ft_strlen(const char *s);- Calculates the length of the strings.char *ft_strchr(const char *s, int c);- Returns a pointer to the first occurrence of the charactercin the strings.char *ft_strrchr(const char *s, int c);- Returns a pointer to the last occurrence of the charactercin the strings.size_t ft_strlcpy(char *dst, const char *src, size_t size);- Copies up tosize - 1characters from the stringsrctodst, NUL-terminating the result.size_t ft_strlcat(char *dst, const char *src, size_t size);- Appends the NUL-terminated stringsrcto the end ofdst.int ft_strncmp(const char *s1, const char *s2, size_t n);- Compares at most the firstnbytes ofs1ands2.char *ft_strnstr(const char *big, const char *little, size_t len);- Locates the first occurrence of the null-terminated stringlittlein the stringbig, where not more thanlencharacters are searched.char *ft_strdup(const char *s);- Returns a pointer to a new string which is a duplicate of the strings.char *ft_substr(char const *s, unsigned int start, size_t len);- Allocates and returns a substring from the strings.char *ft_strjoin(char const *s1, char const *s2);- Allocates and returns a new string, the concatenation ofs1ands2.char *ft_strtrim(char const *s1, char const *set);- Allocates and returns a copy ofs1with the characters specified insetremoved from the beginning and the end.char **ft_split(char const *s, char c);- Allocates and returns an array of strings obtained by splittingsusing the charactercas a delimiter.char *ft_strmapi(char const *s, char (*f)(unsigned int, char));- Applies the functionfto each character of the stringsto create a new string.void ft_striteri(char *s, void (*f)(unsigned int, char*));- Applies the functionfon each character of the strings, passing its index as first argument.
void *ft_memset(void *s, int c, size_t n);- Fills memory with a constant byte.void ft_bzero(void *s, size_t n);- Erases the data in thenbytes of the memory starting at the location pointed to bys, by writing zeros to that area.void *ft_memmove(void *dest, const void *src, size_t n);- Copiesnbytes from memory areasrcto memory areadest(memory areas may overlap).void *ft_memcpy(void *dest, const void *src, size_t n);- Copiesnbytes from memory areasrcto memory areadest(memory areas must not overlap).void *ft_memchr(const void *s, int c, size_t n);- Scans the initialnbytes of the memory area pointed to bysfor the first instance ofc.int ft_memcmp(const void *s1, const void *s2, size_t n);- Compares the firstnbytes of the memory areass1ands2.void *ft_calloc(size_t nmemb, size_t size);- Allocates and zeroes out memory for an array ofnmembelements ofsizebytes each and returns a pointer to the allocated memory.
int ft_atoi(const char *nptr);- Converts the initial portion of the string pointed to bynptrtoint.char *ft_itoa(int n);- Allocates and returns a string representing the integer received as an argument.void ft_putchar_fd(char c, int fd);- Outputs the charactercto the given file descriptor.void ft_putstr_fd(char *s, int fd);- Outputs the stringsto the given file descriptor.void ft_putendl_fd(char *s, int fd);- Outputs the stringsto the given file descriptor followed by a newline.void ft_putnbr_fd(int n, int fd);- Outputs the integernto the given file descriptor.
typedef struct s_list t_list;- The structure representing a node in the linked list, containing avoid *contentand a pointer to the next node.t_list *ft_lstnew(void *content);- Allocates and returns a new node.void ft_lstadd_front(t_list **lst, t_list *new);- Adds the nodenewat the beginning of the list.int ft_lstsize(t_list *lst);- Counts the number of nodes in a list.t_list *ft_lstlast(t_list *lst);- Returns the last node of the list.void ft_lstadd_back(t_list **lst, t_list *new);- Adds the nodenewat the end of the list.void ft_lstdelone(t_list *lst, void (*del)(void*));- Frees the memory of the node's content using thedelfunction and frees the node.void ft_lstclear(t_list **lst, void (*del)(void*));- Deletes and frees the given node and every successor of that node, using the functiondelandfree.void ft_lstiter(t_list *lst, void (*f)(void *));- Iterates the listlstand applies the functionfon the content of each node.t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));- Iterates the listlstand applies the functionfon the content of each node, creating a new list.