Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pin3dev/42_getnextline
A function that reads and returns a single line from a file descriptor, efficiently handling large inputs. This project sharpens skills in dynamic memory allocation, buffer management, and system-level file operations in C programming.
https://github.com/pin3dev/42_getnextline
42-cursus 42-get-next-line 42-gnl 42projects 42school buffer-overflow file-descriptors io memory-management
Last synced: about 2 months ago
JSON representation
A function that reads and returns a single line from a file descriptor, efficiently handling large inputs. This project sharpens skills in dynamic memory allocation, buffer management, and system-level file operations in C programming.
- Host: GitHub
- URL: https://github.com/pin3dev/42_getnextline
- Owner: pin3dev
- Created: 2022-12-14T23:37:37.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T23:28:10.000Z (about 2 months ago)
- Last Synced: 2024-10-26T09:39:37.101Z (about 2 months ago)
- Topics: 42-cursus, 42-get-next-line, 42-gnl, 42projects, 42school, buffer-overflow, file-descriptors, io, memory-management
- Language: C
- Homepage: https://github.com/pin3dev/42_Cursus/blob/68d9f9df36b61a49f1275dcf25ebdc91df19da3c/assets/GetNextLine/Rdm/getNextLine_en.subject.pdf
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
GetNextLine
Introduction •
Structure •
Docs •
Cloning •
Usage •
Norms •
Theoretical
The **Get Next Line** project focuses on reading a file line by line efficiently, which is a common task in many applications. The goal of this project is to write a function that returns the next line from a file descriptor, handling various edge cases such as multiple file descriptors, varying buffer sizes, and memory management.
The main challenge of the project is to ensure that the function handles both large and small files while managing memory efficiently, and avoiding memory leaks or overflows.
The function relies on a few key concepts. **File descriptors** are used to reference files or input/output streams, while **static variables** are necessary to maintain values between function calls. **Buffers** are used to temporarily store data read from the file descriptor, ensuring smooth data flow. Proper **memory management** is also essential to avoid memory leaks by ensuring memory is allocated and freed correctly.
For detailed documentation on the **get_next_line** function, including example usages and edge cases, visit the following link:
To clone this repository and compile the project, run the following commands:
```bash
git clone https://github.com/pin3dev/42_GetNextLine.git
cd 42_GetNextLine
```
This will download the project from GitHub to your local machine. Once inside the directory, you can compile the project with the provided Makefile.### Makefile
The project includes a `Makefile` to streamline the compilation process. The available rules are:
- `all`: Compiles the project.
- `clean`: Removes object files.
- `fclean`: Removes object files and the executable.
- `re`: Recompiles the entire project from scratch.To compile the project, simply run:
```bash
make
```
This will generate the necessary files and allow you to link the function into your project.### Basic Usage
To use the **get_next_line** function in your program:
1. Include the header file in your code:
```c
#include "42_GetNextLine/gnl/inc/get_next_line.h"
```2. Compile your code along with the **get_next_line** files:
```bash
cc -Wall -Wextra -Werror -o your_exec test.c -L 42_GetNextLine/gnl/ -lgnl -L 42_Libft/libft/ -lft
```3. You can now call `get_next_line` to read a file line by line.
```c
int fd = open("file.txt", O_RDONLY);
char *line;
while ((line = get_next_line(fd)) != NULL)
{
printf("%s\n", line);
free(line); // Make sure to free the line after use.
}
close(fd);
return 0;
```## ⚠️ Norms and Guidelines Disclaimer
This project adheres ***partially*** to the strict coding guidelines of the [**42 School Norm**](https://github.com/pin3dev/42_Cursus/blob/b9cd0fe844ddb441d0b3efb98abcee92aee49535/assets/General/norme.en.pdf). This includes coding restrictions like a maximum number of functions per file, limited lines per function, and other stylistic rules which may impact implementation decisions.
All the theoretical material used to develop this project is organized and can be accessed directly via the link below: