This is my C functions library, my first project as a cadet at School 42 São Paulo. It has functions to manipulate strings, memory, and linked list, and I will expand this in the future when necessary.
Makefile
The Makefile will compile the static librarylibft.a
Rules
- all - Make the
libft.a
of the mandatory functions- bonus - Make the
libft.a
of the bonus functions- clean - Delete all the objects(.o) of the folder.
- fclean - Make clean and delete the
libft.a
- re - Remake the
libft.a
The functions is separate in base of they uses or standard library. Some of they is like the originals but others is my specific implementation.
ft_isalpha, ft_isdigit, ft_isalnum, ft_isascii, ft_isprint
Check whether c, which must have the value of an unsigned char or EOF, falls into a certain character class according to the specified locale.ft_isallspace
Check if the char passed is all space.ft_toupper, ft_tolower
Convert lowercase letters to uppercase, and vice versa.
ft_free_ptr
Free a pointer.ft_free_split
Free a double pointer char.ft_free_triple
Free a triple pointer char.ft_set_free_and_null
Set free and null in a char pointer.
ft_lstnew
Allocates (with malloc) and returns a new element. The variable ’content’ is initialized with the value of the parameter ’content’. The variable ’next’ is initialized to NULL.ft_lstadd_front
Adds the element ’new’ at the beginning of the list.ft_lstsize
Counts the number of elements in a list.ft_lstlast
Returns the last element of the list.ft_lstadd_back
Adds the element ’new’ at the end of the list.ft_lstdelone
Takes as a parameter an element and frees the memory of the element’s content using the function ’del’ given as a parameter and free the element. The memory of ’next’ must not be freed.ft_lstclear
Deletes and frees the given element and every successor of that element, using the function ’del’ and free(3). Finally, the pointer to the list must be set to NULL.ft_lstiter
Iterates the list ’lst’ and applies the function ’f’ to the content of each element.ft_lstmap
Iterates the list ’lst’ and applies the function ’f’ to the content of each element. Creates a new list resulting of the successive applications of the function ’f’. The ’del’ function is used to delete the content of an element if needed.
ft_putchar_fd
Outputs the character ’c’ to the given file descriptor.ft_putstr_fd
Outputs the string ’s’ to the given file descriptor.ft_putendl_fd
Outputs the string ’s’ to the given file descriptor, followed by a newline.ft_putnbr_fd
Outputs the integer ’n’ to the given file descriptor.ft_putnbr_base_fd
Outputs the integer ’n’ converted to the specified base to the given file descriptor.
ft_atoi
Converts the initial portion of the string pointed to by nptr to int.ft_calloc
Allocates size bytes and returns a pointer to the allocated memory.ft_itoa
Allocates (with malloc) and returns a string representing the integer received as an argument. Negative numbers must be handled.ft_itoa_base
Allocates (with malloc) and returns a string converted for the base received representing the integer received as an argument. Negative numbers must be handled.
ft_bzero
Erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeroes, (bytes containing '\0') to that area.ft_memset
Fills the first n bytes of the memory area pointed to by s with the constant byte c.ft_memcpy
Copies n bytes from memory area src to memory area dest. The memory areas must not overlap.ft_memccpy
Copies no more than n bytes from memory area src to memory area dest, stopping when the character c is found.ft_memmove
Copies n bytes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.ft_memchr
Scans the initial n bytes of the memory area pointed to by s for the first instance of c. Both c and the bytes of the memory area pointed to by s are interpreted as unsigned char.ft_memcmp
Returns an integer less than, equal to, or greater than zero if the first n bytes of s1 is found, respectively, to be less than, to match, or be greater than the first n bytes of s2.ft_strlen
Calculates the length of the string pointed to by s, excluding the terminating null byte ('\0').ft_strlen_split
Calculates the length of a splitted string pointed to by s, excluding the terminating null byte ('\0').ft_strlcpy
Copies up to size - 1 characters from the NULL-terminated string src to dst, NULL-terminating the result.ft_strlcat
Appends the NULL-terminated string src to the end of dst. It will append at most size - strlen(dst) - 1 bytes, NULL-terminating the result.ft_strchr
Returns a pointer to the first occurrence of the character c in the string s.ft_strrchr
Returns a pointer to the last occurrence of the character c in the string s.ft_strnstr
Locates the first occurrence of the null-terminated string little in the string big, where not more than len characters are searched.ft_strncmp
Compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2.ft_strdup
Returns a pointer to a new string which is a duplicate of the string s. Return NULL if has some error.ft_strdup2
Returns a pointer to a new string which is a duplicate of the string s. Return an empty string if has some error.ft_substr
Allocates (with malloc) and returns a substring from the string ’s’. The substring begins at index ’start’ and is of maximum size ’len’.ft_strjoin
Allocates (with malloc) and returns a new string, which is the result of the concatenation of ’s1’ and ’s2’.ft_strtrim
Allocates (with malloc) and returns a copy of ’s1’ with the characters specified in ’set’ removed from the beginning and the end of the string.ft_split
Allocates (with malloc) and returns an array of strings obtained by splitting ’s’ using the character ’c’ as a delimiter. The array must be ended by a NULL pointer.ft_split_rev
Join a splited string.ft_concatenate_join
Concatenate the first argument with the second using join.
ft_strmapi
Applies the function ’f’ to each character of the string ’s’ to create a new string (with malloc(3)) resulting from successive applications of ’f’.ft_find_index
Go through the first parameter and find the c passed as second parameter. If the c is find it return the position otherwise returns -1.ft_line
Take the s parameter and copy n characters specified in second parameter and put the terminate null '\0'.ft_line
Swap to int pointers.get_next_line
Return a line of the file descriptor passed. Return 1 if find a line, -1 if has an error, 0 if is the last line.