Skip to content

get_next_line is a C function that reads one line at a time from a file descriptor. It supports configurable buffer sizes, persistent state across function calls, and (in the bonus version) multiple file descriptors simultaneously, while ensuring safe memory handling.

Notifications You must be signed in to change notification settings

cmunoz-g/get_next_line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📜 get_next_line

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.

Build and run

# Clone
 git clone https://github.com/cmunoz-g/get_next_line.git
 cd get_next_line

Include in your project by adding:

  • get_next_line.c
  • get_next_line_utils.c
  • get_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_program

Replace 42 with the buffer size you want.

Run your program:

./my_program

Features

  • Line-by-line reading — returns each line including \n if 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.

Project structure

  • get_next_line.c — main line-reading logic.
  • get_next_line_utils.c — helper functions.
  • get_next_line.h — prototypes and includes.

Bonus

  • Multiple file descriptors — supports parallel reads from multiple descriptors, storing state separately.

About

get_next_line is a C function that reads one line at a time from a file descriptor. It supports configurable buffer sizes, persistent state across function calls, and (in the bonus version) multiple file descriptors simultaneously, while ensuring safe memory handling.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages