This project has been created as part of the 42 curriculum by yoben-ch.
Libft is a custom C static library created for the 42 curriculum. Its goal is to reimplement a selection of standard C library functions, add useful string and memory utilities, and provide a small linked-list API that can be reused in later C projects.
The project builds a static archive named libft.a. All source files are written
in C, follow the 42 Norm, and are compiled with cc using -Wall -Wextra -Werror.
This library contains three groups of functions.
These functions reproduce the behavior of their standard C library equivalents,
using the ft_ prefix:
- Character checks and conversion:
ft_isalpha,ft_isdigit,ft_isalnum,ft_isascii,ft_isprint,ft_toupper,ft_tolower - Memory functions:
ft_memset,ft_bzero,ft_memcpy,ft_memmove,ft_memchr,ft_memcmp,ft_calloc - String functions:
ft_strlen,ft_strlcpy,ft_strlcat,ft_strchr,ft_strrchr,ft_strncmp,ft_strnstr,ft_strdup - Conversion:
ft_atoi
The character classification functions return 1 when the character matches
the tested class and 0 otherwise, as required by the subject.
These functions provide common operations that are useful in later projects:
ft_substr: creates a substring from a stringft_strjoin: joins two strings into a new allocated stringft_strtrim: trims characters from the beginning and end of a stringft_split: splits a string into a NULL-terminated array of stringsft_itoa: converts an integer to a stringft_strmapi: creates a new string by applying a function to each characterft_striteri: applies a function to each character in placeft_putchar_fd,ft_putstr_fd,ft_putendl_fd,ft_putnbr_fd: write output to a file descriptor
The library defines the following list structure in libft.h:
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;It also implements these list helpers:
ft_lstnewft_lstadd_frontft_lstsizeft_lstlastft_lstadd_backft_lstdeloneft_lstclearft_lstiterft_lstmap
Compile the library from the repository root:
makeThis creates:
libft.a
Clean object files:
make cleanClean object files and the static library:
make fcleanRebuild the project from scratch:
make reTo use the library in another C file, include the header and link the archive:
#include "libft.h"cc -Wall -Wextra -Werror main.c libft.a- No global variables are used.
- Helper functions, when needed, are declared
static. - The library is created with
ar. libtoolis not used.- The Makefile provides the required rules:
all,clean,fclean, andre. - The submitted files are the Makefile,
libft.h, andft_*.csource files.
manpages for the standard C library functions reimplemented in this project- The 42 Libft subject, version 19.2
- The OpenBSD manual pages for
strlcpyandstrlcat - The GNU C Library documentation
- The C reference documentation at cppreference.com