Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mushigarou/get_next_line
Get_Next_Line() a function that returns a line read from a file descriptor.
https://github.com/mushigarou/get_next_line
file-descriptors static-variables unix
Last synced: about 1 month ago
JSON representation
Get_Next_Line() a function that returns a line read from a file descriptor.
- Host: GitHub
- URL: https://github.com/mushigarou/get_next_line
- Owner: Mushigarou
- License: mit
- Created: 2022-12-07T05:23:43.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-15T03:32:37.000Z (7 months ago)
- Last Synced: 2024-11-05T18:14:37.609Z (3 months ago)
- Topics: file-descriptors, static-variables, unix
- Language: C
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Get Next Line
get_next_line function developed using only one static variable allows you to read a file (not binary), one line at a time. The function returns the line that was read, or NULL if there is nothing else to read or if an error occurred.
```c
char *get_next_line(int fd);
```## Usage:
1 - Include the get_next_line.h header file
2 - Compile your code using the -D BUFFER_SIZE=n flag, where n is the desired buffer size for the read() function. This flag should be added as a flag to the compiler.
```
$> cc -Wall -Wextra -Werror -D BUFFER_SIZE=n .c
```
You can choose the default value for the buffer size by not giving the `-D` flag.## Multiple File Descriptors
The get_next_line (Bonus) function can handle multiple file descriptors simultaneously. This means you can read from different file descriptors in separate calls without losing the reading thread of each file descriptor or returning a line from another file descriptor.```c
while (1)
{
while ((s = get_next_line(fd)))
printf("te.txt : %s", s);
while ((x =get_next_line(f)))
printf("t.txt : %s", x);
while ((k =get_next_line(t)))
printf("get_next_line_utils.txt : %s", k);
if (!s && !k && !x)
break;
}
```## Note on File Changes and Binary Files
If the file pointed to by the file descriptor changes between consecutive calls to get_next_line, while read() has not reached the end of the file, the function's behavior is undefined.### This project is licensed under the MIT license