Skip to content

Expl0-it/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

171 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Libft

A custom implementation of essential C standard library functions, developed as part of the 42 School curriculum. This project serves as a foundational toolkit for future C programming projects, providing a deep understanding of low-level memory management, string manipulation, and data structures.


📖 Overview

Libft is a personal recreation of commonly used functions from the standard C library (libc), along with additional utility functions. The goal is to build a reusable library that can be used across multiple projects.

This project focuses on:

  • Rewriting standard C functions from scratch
  • Understanding how fundamental operations work internally
  • Building reliable, reusable code
  • Learning proper memory management and debugging techniques

🧠 Learning Objectives

By completing this project, you will gain experience with:

  • Low-level memory manipulation
  • String handling and processing
  • Pointer arithmetic
  • Dynamic memory allocation (malloc, free)
  • Linked list implementation
  • Code modularity and reusability
  • Writing clean and maintainable C code

📂 Project Structure

libft/
├── ft_*.c        # Core library functions
├── ft_*.h        # Header file(s)
├── Makefile      # Build system
└── README.md

The project typically includes:

  • Part 1: Reimplementation of standard libc functions
  • Part 2: Additional utility functions
  • Bonus: Linked list manipulation functions

🔧 Core Functions

🔹 Memory Functions

  • ft_memset
  • ft_bzero
  • ft_memcpy
  • ft_memmove
  • ft_memchr
  • ft_memcmp

🔹 String Functions

  • ft_strlen
  • ft_strdup
  • ft_strcpy / ft_strlcpy
  • ft_strcat / ft_strlcat
  • ft_strchr / ft_strrchr
  • ft_strncmp
  • ft_substr
  • ft_strjoin
  • ft_split
  • ft_strtrim

🔹 Character Checks & Conversions

  • ft_isalpha
  • ft_isdigit
  • ft_isalnum
  • ft_isascii
  • ft_isprint
  • ft_toupper
  • ft_tolower

🔹 Conversion Functions

  • ft_atoi
  • ft_itoa

🔹 Output Functions

  • ft_putchar_fd
  • ft_putstr_fd
  • ft_putendl_fd
  • ft_putnbr_fd

🌟 Bonus Part — Linked Lists

Implementation of a simple singly linked list structure:

typedef struct s_list
{
    void            *content;
    struct s_list   *next;
} t_list;

Linked List Functions

  • ft_lstnew
  • ft_lstadd_front
  • ft_lstsize
  • ft_lstlast
  • ft_lstadd_back
  • ft_lstdelone
  • ft_lstclear
  • ft_lstiter
  • ft_lstmap

⚙️ Compilation & Usage

To build the library:

make

This will generate:

libft.a

Cleaning

make clean      # Remove object files
make fclean     # Remove object files + library
make re         # Rebuild everything

🚀 How to Use

  1. Include the header in your project:
#include "libft.h"
  1. Compile your program with the library:
gcc main.c libft.a -o program

🧪 Example

#include "libft.h"
#include <stdio.h>

int main(void)
{
    char *str = ft_strdup("Hello, Libft!");
    printf("%s\n", str);
    free(str);
    return 0;
}

📌 Requirements

  • C compiler (example: GCC, clang)
  • Make
  • UNIX-based system (Linux/macOS recommended)

🎯 Key Concepts Covered

Category Topics
Memory Management Allocation, deallocation, raw memory ops
Strings Manipulation, parsing, transformation
Data Structures Linked lists
Low-Level C Pointers, buffers, manual control
Code Design Modularity and reusable libraries

🚀 Purpose of the Project

The Libft project is designed to:

  • Build a strong foundation in C programming
  • Understand how standard library functions work internally
  • Create a reusable library for future projects
  • Improve debugging and problem-solving skills

⚠️ Notes

  • All functions are implemented from scratch (no direct use of libc equivalents)
  • Pay close attention to memory leaks and edge cases
  • Follow coding standards (e.g., 42 Norm if applicable)

🤝 Contributing

Contributions and improvements are welcome!

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

📄 License

This project is for educational purposes. Refer to the repository for licensing details (if provided).


📚 Resources

To deepen your understanding:

  • C standard library documentation
  • Manual pages (man malloc, man strlen, etc.)
  • Memory management guides
  • Data structures and algorithms basics

About

rewriting libc and other useful functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors