Reusable C building blocks with an in-repo tester tuned for 42 project evaluations.
- At a Glance
- About This Library
- Subject Compliance
- Repository Layout
- Build & Integration
- Usage Guidelines
- Feature Deep Dive
- Input & Validation
- Rendering & Output
- Internal Architecture
- Tester Workflow
- Results & Reporting
Highlights: Static C library covering all mandatory libft calls plus field-tested helpers.
- Ships 40+ string, memory, FD, conversion, and list routines backed by
libft.a. - Adds practical extras (
ft_atol,ft_isnumeric,ft_max,ft_str_append_char) proven useful in later 42 milestones. - Bundles local copies of
printf/andgnl/so dependent projects link without external fetches during defense. - Includes a colorized regression tester under
.testers/libftto preflight submissions.
Highlights: Norm-compliant foundations with pragmatic ergonomics.
- Written in pure C, respecting 42 Norm guidelines and minimal dependencies (standard headers only inside
libft/). - Favors readability: short helpers like
ft_words_counterkeep complex flows (e.g.,ft_split) approachable for peer review. - Optional utilities sit alongside mandatory functions but remain header-gated so downstream repos can opt in selectively.
- Memory ownership is explicit—every allocator returns heap pointers that callers must release (tester cross-checks accidental leaks).
Highlights: Matches the scope mandated in
docs/subject_libft.pdfwhile flagging deviations.
- Mandatory Part 1/2 functions mirror prototypes and behavior described on pages 7–12 of the subject PDF.
- Bonus linked-list API implements the full
t_listtoolchain inlibft/, meeting bonus segregation rules. - Makefile exposes
all,clean,fclean, andre, compiles with-Wall -Wextra -Werror, and avoids needless relinks via object caching inobj/. - Extra helpers stay within subject constraints; only
ft_swapstrscurrently behaves as a pointer swap stub (planned refinement noted below).
Covered functions
- Character/ctype checks, core string/memory routines, conversion helpers, FD printers
- Full linked-list API (
ft_lst*) with content-aware assertions and cleanups - Current scope excludes newer helpers like
ft_isnumericorft_str_append_char; see Feature Deep Dive for intended expansion
Highlights: Flat structure keeps evaluation navigation fast.
docs/subject_libft.pdf— official 42 brief kept alongside the repo for audits.libft/— implementation sources pluslibft.hcovering mandatory and bonus APIs..testers/libft/— tester harness (tests.c,functions/,run_tests.sh,results.txt).printf/&gnl/— local working copies cloned once, stripped of history, ready for downstream linking.obj/— build artifacts created by the Makefile; safe to delete viamake clean.libft.a— compiled static archive; regenerated on eachmake.
Highlights: Default target prepares dependencies then produces
libft.a.
makeensuresprintf/andgnl/exist (cloning only if missing), createsobj/, and archives every.ointolibft.a.make cleanclears objects,make fcleanalso removeslibft.aplus the cloned dependency folders for a true fresh start.make rechainsfcleanthenall, rebuilding the full toolchain in one go.- Compilation stays deterministic: no hidden flags, and every translation unit uses the same warning set.
make # build libft.a (clones printf/gnl if absent)
make clean # remove obj/
make fclean # clean + remove libft.a, printf/, gnl/
make re # force pristine rebuildHighlights: Intended for reuse across 42 repos without manual tweaking.
- Include with
#include "libft/libft.h"or adjust include paths to suit your project layout. - Link the archive via
cc your_main.c ../libft.aor add-L/-lftflags inside larger build systems. - Keep helper usage optional: if a downstream subject forbids extras, only call functions present in the official PDF.
- Re-run
.testers/libft/run_tests.shafter edits; failed cases flag mismatches immediately throughresults.txt.
Highlights: Modular helpers organized by use case.
- String toolkit ranges from safe copying (
ft_strlcpy,ft_strlcat) to builders (ft_strjoin,ft_strtrim,ft_split). - Memory primitives (
ft_memset,ft_bzero,ft_memcpy,ft_memmove,ft_calloc) offer low-level control without hidden allocations. - Numeric conversions include defensive parsing (
ft_atoi,ft_atol) and formatting viaft_itoafor FD output helpers. - Linked-list suite (
ft_lstnewthroughft_lstmap) follows the subject spec, with tester coverage for iterator/map corner cases.
Helper spotlight
ft_isnumericvalidates optional sign + digits for gatekeeping user input before conversion.ft_str_append_charrebuilds buffers incrementally; it frees the old pointer on failure to prevent leaks.ft_swapstrscurrently swaps pointer values locally; plan to extend it to swap caller buffers once references are passed by address.ft_maxprovides a tiny arithmetic utility for readability when normalizing bounds.
Highlights: Tolerant parsing with explicit whitespace handling.
ft_iswhitespaceandft_isspacedistinguish control-space vs. literal space to tune tokenizers.ft_atoirejects duplicate leading signs (--,++) to avoid silent UB before conversion.ft_atolmirrors that behavior for wider ranges, enabling safe bounds checks before casting back toint.ft_isnumerictreats standalone signs as invalid, ensuring only well-formed numeric strings pass validation.
Edge-case considerations
- Current converters do not guard against multiplication overflow; confirm input spans before calling on untrusted data.
- Whitespace helpers return
bool/intaccording to their prototypes, so prefer them over duplicating ASCII tables.
Highlights: File-descriptor oriented presentation utilities.
ft_putchar_fd,ft_putstr_fd,ft_putendl_fd, andft_putnbr_fdcentralize writes for stdout/stderr or custom descriptors.```sh cd .testers/libft ./run_tests.sh
- Tester fixtures open temp files to confirm exact byte sequences and clean them post-run.
- `ft_strmapi` and `ft_striteri` support character-by-character transformations, handy before printing formatted strings.
- Combined with `ft_printf` (bundled sibling repo), `libft.a` covers both low-level writes and formatted output pipelines.
## Internal Architecture
> **Highlights:** Simple directory discipline keeps maintenance low.
- `libft.h` declares every public symbol and `t_list` struct, keeping prototypes centralized for IDE assistance.
- Object files live in `obj/` with filenames derived via `$(notdir ...)`, preventing collisions across modules.
- The Makefile defers `lib` compilation until directories exist, ensuring `printf/` and `gnl/` remain in sync without recursive makes.
- Bonus sources share the primary folder; `_bonus` naming is unnecessary because the subject allows this layout for libft.
## Tester Workflow
> **Highlights:** Mirrors evaluator behavior start-to-finish.
- Builds a test binary (`tests`) alongside `libft.a`, keeping artifacts inside `.testers/libft` for easy cleanup.
- Executes every function suite sequentially, writing verdicts to `results.txt` for archival or sharing with peers.
- Highlights failures immediately with expected vs. actual values in the same line for quick debugging.
- Relies on `libbsd` only for reference implementations (`strlcpy`, `strlcat`); macOS users already have them in libc.
<details>
<summary>Extending coverage</summary>
- Add new `.c` files under `.testers/libft/functions/` and declare their prototypes in `tester.h` to include them in the sweep.
- Re-run the script; the `find` command auto-discovers added tests without touching the Makefile.
</details>
## Results & Reporting
> **Highlights:** Actionable logs without noise.
- `results.txt` collects one line per function (SUCCESS/KO with context) so reviewers can skim outcomes quickly.
- `run_tests.sh` streams colored copies of those lines to stdout and ends with a success/total tally.
- Failures display expected vs. actual payloads (buffers, substrings, numeric values) to reduce reproduction time.
- Clean-up step deletes temporary FD fixtures, keeping the tester tree tidy between runs.
```sh
sed -n '1,10p' .testers/libft/results.txt # quick glance after a run
Next steps after a failure
- Re-run the relevant test file directly under
ccwith-gif you need to attachlldborgdb. - Compare against glibc/bsd behavior using the inline references already present inside each tester function.