- ๐ Table of Contents
- ๐ Overview
- ๐ฆ Features
- ๐ repository Structure
- โ๏ธ Modules
- ๐ Getting Started
- ๐ฃ Roadmap
- ๐ค Contributing
- ๐ License
- ๐ Acknowledgments
The get_next_line
project is a programming exercise that challenges you to implement a function capable of reading a line from a file descriptor. The primary goal is to develop a function that allows reading from a file descriptor efficiently, providing a line-by-line extraction from the given input. This project introduces the concept of static variables and encourages a deeper understanding of memory management and file I/O in the C programming language.
- Prototype:
char *get_next_line(int fd);
- Parameters:
- ๐
fd
: The file descriptor to read from.
- ๐
- Return value:
- ๐ Read line: Returns the next line from the specified file descriptor.
๐ซ NULL
: Indicates there is nothing else to read or an error occurred.
- External functions:
๐ read
,๐ ๏ธ malloc
,๐๏ธ free
- Description: Writes a function that reads from a file descriptor (
fd
) and returns the next line of text.
โโโ get_next_line/
โโโ get_next_line.c
โโโ get_next_line.h
โโโ get_next_line_bonus.c
โโโ get_next_line_bonus.h
โโโ get_next_line_utils.c
โโโ get_next_line_utils_bonus.c
Mandatory
File | Summary |
---|---|
get_next_line.c | Implements the core functionality of get_next_line . Reads a line from the given file descriptor and manages the linked list operations to handle line reading. It uses utility functions to efficiently handle dynamic memory allocation, buffer reading, and linked list manipulation. The function provides an interface for retrieving the next line from a file. |
get_next_line_utils.c | Contains utility functions used in the implementation of get_next_line . The key functionalities include checking for a newline character in a linked list node, finding the last node in a linked list, adding a new node to the end of a linked list, calculating the length of content in a linked list until a newline character, and clearing the memory allocated for nodes in a linked list. These utilities contribute to the overall functionality of reading lines from a file. |
get_next_line.h | Header file defining the struct t_list and function prototypes for get_next_line and associated utilities. The struct t_list represents a linked list node containing the content of a line and a pointer to the next node. The function prototypes include those for reading lines, managing linked lists, and handling memory. This header provides the necessary interface for using the get_next_line function and associated utilities. |
Bonus
File | Summary |
---|---|
get_next_line_bonus.c | The get_next_line_bonus.c file extends the core functionality of get_next_line by introducing features that enable the simultaneous management of multiple file descriptors (fd ). The primary change occurs in the get_next_line function, where it now maintains a static array of linked lists (lst ) corresponding to different file descriptors. This allows the system to handle and track the state of each file descriptor independently, ensuring seamless reading of lines from multiple sources concurrently. The file orchestrates the flow and integration of these features, coordinating the initialization, reading, and cleanup processes for each file descriptor. |
get_next_line_utils_bonus.c | Contains utility functions unchanged from the mandatory implementation. These functions facilitate the core operations related to linked lists and memory management and are reused in the bonus implementation to maintain consistency and code modularity. They contribute to the effective management of linked lists within the extended get_next_line system, supporting operations like checking for newline characters, obtaining the last node, adding nodes, calculating length until newline, and clearing nodes. |
get_next_line_bonus.h | Header file for the bonus functionality, defining additional structs and function prototypes. The changes in the header are minimal and involve introducing the necessary structures and functions to support the concurrent management of multiple file descriptors. It extends the structures and functions defined in the mandatory header (get_next_line.h ) to accommodate the new requirements. The header file ensures that the core functionality remains intact while providing an interface for the bonus features to seamlessly integrate with the existing system. |
Dependencies
Please ensure you have the following dependencies installed on your system:
-
โน๏ธ C Compiler: You will need a C compiler to build and run the project.
- Example for GCC (GNU Compiler Collection):
sudo apt-get install gcc # Ubuntu sudo yum install gcc # CentOS
- Example for GCC (GNU Compiler Collection):
- Clone the get_next_line repository:
git clone https://github.com/San-tito/get_next_line
- Change to the project directory:
cd get_next_line
- Compile the dependencies:
gcc -Wall -Werror -Wextra -D BUFFER_SIZE=42 get_next_line*.c -o gnl
./gnl file.txt
/* Not implemented */
โน๏ธ Task 1: Implement handling of multiple file descriptors at the same time
โน๏ธ Task 2: Implement tests
โน๏ธ ...
Contributions are welcome! Here are several ways you can contribute:
- Submit Pull Requests: Review open PRs, and submit your own PRs.
- Join the Discussions: Share your insights, provide feedback, or ask questions.
- Report Issues: Submit bugs found or log feature requests for SAN-TITO.
This project is protected under the UNLICENSE License. For more details, refer to the LICENSE file.
- Master File I/O Operations
- get_next_line explained: develop a function that reads a file line by line
- gnlTester