Mandatory part of 42’s get_next_line: read a file descriptor one line at a time.
Returns a newly allocated string, or NULL on EOF/error.
Bonus part of 42’s get_next_line: supports multiple FDs concurrently by keeping per-FD state.
char *get_next_line(int fd);Run 'make' to compile both mandatory get_next_line function or 'make bonus'. This would create a static library called libgnl.a or libgnl_bonus.a respectively. BUFFER_SIZE is possible to change during compilation process.
make
# or override:
make BUFFER_SIZE=4096Add as a header into your program
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include "get_next_line.h"
int main(void)
{
int fd = open("Makefile", O_RDONLY);
char *line;
if (fd < 0) return 1;
while ((line = get_next_line(fd)) != NULL)
{
printf("%s", line);
free(line);
}
close(fd);
return 0;
}Compile and run your program
cc main.c libgnl.a -o gnl_test
./gnl_test