Skip to content

hanmpark/get_next_line

Repository files navigation

get_next_line

A function that reads from a file descriptor line by line.


Repository created at Repository code size Mostly used language

Description

The get_next_line project introduces dynamic memory allocation, buffer management, and file descriptor handling.

The goal is to implement a function that reads one line at a time from a file descriptor without loading the entire file into memory. This makes it possible to process large files efficiently and handle multiple file descriptors simultaneously.

🛠️ Features

  • Reads from a file descriptor line by line.
  • Handles dynamic memory allocation for variable-length lines.
  • Manages multiple file descriptors at the same time.
  • Stops reading at newline (\n) or EOF.
  • Safe and efficient buffer handling.

Function Prototype

char *get_next_line(int fd);

📦 Installation

Clone the repository and compile the project:

git clone https://github.com/hanmpark/get_next_line.git
cd get_next_line
make

This will build the project with the default BUFFER_SIZE.

🚀 Usage

Compile with a custom buffer size if needed:

cc -Wall -Wextra -Werror -D BUFFER_SIZE=42 <files>.c

Call the function inside your program:

char *line;
int fd = open("file.txt", O_RDONLY);

line = get_next_line(fd);
while (line)
{
    printf("%s", line);
    free(line);
    line = get_next_line(fd);
}
close(fd);

👤 Authors

About

A simple function that returns a line read from a file descriptor

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages