Custom implementation of a function that reads one line at a time from a file descriptor. Handles variable buffer sizes, maintains state across calls, and supports multiple file descriptors in the bonus version.
# Clone
git clone https://github.com/cmunoz-g/get_next_line.git
cd get_next_lineInclude in your project by adding:
get_next_line.cget_next_line_utils.cget_next_line.h
Compile with a specified buffer size:
gcc -Wall -Werror -Wextra -D BUFFER_SIZE=42 main.c get_next_line.c get_next_line_utils.c -o my_programReplace 42 with the buffer size you want.
Run your program:
./my_program- Line-by-line reading β returns each line including
\nif present. - Static state β keeps track of leftovers across multiple calls.
- Configurable buffer size β controlled at compile time with
BUFFER_SIZE. - Memory safety β manages dynamic memory to prevent leaks.
- get_next_line.c β main line-reading logic.
- get_next_line_utils.c β helper functions.
- get_next_line.h β prototypes and includes.
- Multiple file descriptors β supports parallel reads from multiple descriptors, storing state separately.