Skip to content

🧱 libft (42 Paris) β€” Rebuild of essential C standard library functions + extra utilities & linked list management (unit tests and memory-leak checks included).

guillaumeast/42_libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧱 libft β€” 42 Paris Project

Rebuilding the fundamental bricks of the C standard library and creating a personal reusable library for all future 42 projects.

Language: C Type: Library Platform: macOS/Linux Status: To be graded


πŸŽ“ Context

This project is one of the very first steps of the 42 Paris curriculum.
Its goal is to reimplement essential C standard library functions (strlen, memcpy, strchr, etc.) as well as a few extra utilities, in order to build a personal base library: libft.

This library will be reused in all upcoming 42 projects (like ft_printf, minishell, push_swap, etc.) and serves as the foundation for all future C exercises.


βš™οΈ Objective

  • Recreate basic string, memory, and character manipulation functions.
  • Implement additional utility functions (ft_split, ft_strjoin, ft_itoa, etc.).
  • Add linked list management functions (ft_lst*) for the bonus part.
  • Provide a reliable, optimized, and memory-leak-free static library.

πŸ—‚οΈ Repository structure

libft/
β”œβ”€β”€ Makefile                     # Compiles the lib, tests, and memcheck binaries
β”œβ”€β”€ libft.h                      # Main header file
β”œβ”€β”€ ft_*.c                       # All lib functions (mandatory + bonus)
β”œβ”€β”€ subject/                     # Official 42 subject
β”‚   └── 2022.libft.en.subject.pdf
└── tests/
    β”œβ”€β”€ mandatory_unit_tests/    # Criterion tests for mandatory functions
    β”œβ”€β”€ bonus_unit_tests/        # Criterion tests for bonus functions
    β”œβ”€β”€ mandatory_memcheck.c     # Main for memory leak tests (mandatory part)
    β”œβ”€β”€ bonus_memcheck.c         # Main for memory leak tests (bonus part)
    └── run_*                    # Generated executables (tests & memcheck)

The naming strictly follows 42 subject conventions:
ft_functionname.c for each function and libft.h as the main entry point.


🧰 Available Make commands

Command Description
make Build libft.a (mandatory functions only).
make bonus Add bonus objects (ft_lst*) to libft.a.
make test Build & run Criterion tests (mandatory).
make test_bonus Build & run Criterion tests (mandatory + bonus).
make leaks Build a memcheck binary (mandatory) and run leaks (macOS) or valgrind (Linux).
make leaks_bonus Same as above for the bonus part.
make clean Remove only object files (.o).
make fclean Remove all objects and binaries (libft.a, run_tests, run_memcheck).
make re Clean everything and rebuild from scratch.
make help Display available commands, OS detection, compiler flags, and Criterion libraries.

πŸ’‘ make help also displays:

  • The detected OS (macOS / Linux)
  • The Criterion flags and linked libraries
  • A summary of all useful targets

πŸ§ͺ Unit tests

All tests are written using the Criterion framework.
They check each function independently, including edge cases and segmentation faults.

Two test suites exist:

  • mandatory_unit_tests/ β†’ standard libc-like functions
  • bonus_unit_tests/ β†’ linked list (ft_lst*) functions

πŸ“¦ Compilation

make test
# or
make test_bonus

🧹 Memory leak verification

make leaks
# or
make leaks_bonus

πŸ”§ Installing dependencies

πŸ§ͺ Criterion

macOS (via Homebrew)

brew install criterion

Ubuntu / Debian

sudo apt update
sudo apt install libcriterion-dev

🧠 Memory check tools

macOS

leaks is included with the Xcode Command Line Tools.

xcode-select --install

Ubuntu / Debian

sudo apt install valgrind

The Makefile automatically detects the correct tool using uname:

  • macOS β†’ uses leaks
  • Linux β†’ uses valgrind

β€œBuild your own standard library, and you’ll never fear undefined behavior again.” πŸ™ƒ

About

🧱 libft (42 Paris) β€” Rebuild of essential C standard library functions + extra utilities & linked list management (unit tests and memory-leak checks included).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published