Personal C standard library implementation for the 42 curriculum. This project re-implements a subset of the C standard library functions and provides additional utilities frequently used in later projects.
Repository: https://github.com/otmansabir/libft
- Re-implementations of common libc functions
- Safe string and memory utilities
- Character checks and conversions
- I/O helpers that write to file descriptors
- Optional “bonus” linked list API (
t_list
) - Static library output:
libft.a
- A POSIX-compatible environment (Linux/macOS)
make
gcc
orclang
- Build the mandatory part:
make
- Build with bonus (linked list) part:
make bonus
- Clean object files:
make clean
- Remove objects and the library:
make fclean
- Full rebuild:
make re
This produces libft.a
at the project root.
Include the project header and link against the built library:
#include "libft.h"
#include <stdio.h>
int main(void)
{
const char *s = "Hello 42 Network";
char **parts = ft_split(s, ' ');
for (size_t i = 0; parts && parts[i]; ++i) {
printf("[%s]\n", parts[i]);
free(parts[i]);
}
free(parts);
printf("len: %zu\n", ft_strlen("libft"));
int n = ft_atoi(" -42");
char *as = ft_itoa(n);
printf("atoi: %d itoa: %s\n", n, as);
free(as);
return 0;
}
Compile and link:
# From the repository root after running `make`
gcc -Wall -Wextra -Werror -I. main.c -L. -lft -o demo
./demo
If your project has a different include layout, adjust -I
accordingly.
Below is the typical scope of a 42 libft. Exact availability depends on the implementation in this repository.
ft_isalpha
,ft_isdigit
,ft_isalnum
,ft_isascii
,ft_isprint
ft_toupper
,ft_tolower
ft_memset
,ft_bzero
,ft_memcpy
,ft_memmove
,ft_memchr
,ft_memcmp
ft_calloc
ft_strlen
,ft_strlcpy
,ft_strlcat
ft_strchr
,ft_strrchr
,ft_strncmp
,ft_strnstr
,ft_strdup
- Additional utilities:
ft_substr
,ft_strjoin
,ft_strtrim
,ft_split
,ft_itoa
,ft_strmapi
,ft_striteri
ft_atoi
ft_putchar_fd
,ft_putstr_fd
,ft_putendl_fd
,ft_putnbr_fd
If the bonus part is included, a singly linked list API with:
t_list
node structureft_lstnew
,ft_lstadd_front
,ft_lstsize
,ft_lstlast
ft_lstadd_back
,ft_lstdelone
,ft_lstclear
ft_lstiter
,ft_lstmap
A common structure for libft:
libft.h
— public headerMakefile
— build rules producinglibft.a
*.c
— function implementations- (Optional)
bonus/*.c
— linked list functions
Your repository may group files differently, but the library target remains libft.a
.
You can write your own small test programs (like main.c
above) or use community testers. Popular options:
- alelievr/libft-unit-test
- jtoty/Libftest
- 42Paris/42FileChecker
- y3ll0w42/libft-war-machine
Note: These external testers may have their own expectations; ensure your function behavior matches the 42 subject.
- Code adheres to the 42 Norm where applicable.
- All allocations should be paired with proper
free
calls by the caller when ownership is transferred (e.g.,ft_split
,ft_itoa
,ft_strdup
, etc.). - Functions are designed to be compatible with later 42 projects.
No license specified in the repository. If you plan to reuse or distribute, consider adding a LICENSE file.
- otmansabir — https://github.com/otmansabir