MyLib is a comprehensive static library written in C. It consolidates essential system-level programming tools into a modular architecture, providing optimized implementations of standard utilities, formatted output, and buffered I/O.
This library was engineered to serve as a standalone foundation for C projects, replacing the standard libc in environments where external dependencies are restricted. It offers granular control over memory allocation, string manipulation, and file descriptor handling.
The library is organized into three distinct, high-performance modules:
A complete re-implementation of the standard printf function, handling variadic arguments and buffer management without external libraries.
- Prototype:
int ft_printf(const char *format, ...); - Variadic Parsing: Utilizes
stdarg.hto process variable argument lists. - Type Support:
%c(Char),%s(String),%p(Pointer address)%d,%i(Signed Decimal)%u(Unsigned Decimal)%x,%X(Hexadecimal Lower/Upper)
- Advanced Flag Management:
- Precision/Width:
.(Precision),[number](Minimum width). - Padding/Alignment:
-(Left align),0(Zero padding). - Prefixes:
#(Hex prefix),+(Force sign),space(Space for positive).
- Precision/Width:
An advanced file reading utility designed to read content line-by-line from file descriptors, solving the problem of reading files of unknown size without high-level abstractions.
- Prototype:
char *get_next_line(int fd); - Multi-FD Support: Capable of managing multiple file descriptors simultaneously (e.g., reading from a network socket and a log file concurrently) without losing thread context.
- Static Persistence: Utilizes static variables to maintain the read buffer state between function calls.
- Memory Efficiency: Dynamic buffer allocation prevents stack overflow on large reads.
A collection of over 40 functions re-implementing ctype.h, string.h, and stdlib.h behaviors for granular control over memory.
This component also includes several custom utility functions, extending the core API beyond the standard libc equivalents.
- Memory Manipulation:
memset,memcpy,memmove(overlap safe),calloc(zero-initialized),bzero. - String Operations:
strlen,strlcpy,strlcat,strnstr,strdup,strjoin,split. - Type Conversion:
atoi,itoa. - Data Structures: A generic Linked List implementation (
t_list) for managing dynamic collections of data (lstnew,lstadd,lstmap,lstiter).
The project maintains a clean separation of concerns for modular integration:
my_lib/
├── Makefile
├── Libft/ # Standard utilities, Memory & Lists
│ ├── libft.h
│ └── ...
├── ft_printf/ # Formatted output logic
│ ├── ft_printf.h
│ └── ...
└── get_next_line/ # Buffered Reader (Bonus version)
├── get_next_line_bonus.h
└── ...
Run make at the root of the repository to compile all modules into a single static archive (my_lib.a or similar).
makeTo use the library in your project, include the specific module headers relative to the library root to ensure namespace clarity:
/* Core Utilities */
#include "my_lib/Libft/libft.h"
/* Formatted Output */
#include "my_lib/ft_printf/ft_printf.h"
/* Buffered I/O Reader */
#include "my_lib/get_next_line/get_next_line_bonus.h"Compile your project by linking the static library.
gcc main.c my_lib/my_lib.a -o my_program- No Memory Leaks: Every allocation is tracked. The library is tested with Valgrind to ensure complete memory safety.
- Modularity: Functions are separated into individual files to minimize binary size during linking.
- Error Handling: Robust protection against NULL pointers and invalid file descriptors.