This project aims to develop a function that returns a line read from a file descriptor. It will help you learn about static variables in C and add a useful function to your collection.
- The project must be written in C and conform to the coding norm.
- Functions should not stop unexpectedly (segmentation fault, bus error, etc.) except for undefined behaviors.
- All heap-allocated memory must be properly freed when necessary. No leaks will be tolerated.
- A Makefile must be provided, compiling the source files with appropriate flags and not relinking.
- The Makefile must contain at least the rules:
$(NAME),all,clean,fclean, andre.
Implement the function get_next_line() that reads a line from a file descriptor.
- Function name:
get_next_line - Prototype:
char *get_next_line(int fd); - Files to turn in:
get_next_line.h,get_next_line.c,get_next_line_utils.c - Parameters:
fd- The file descriptor to read from - Return value: The line read, or
NULLif nothing else to read or an error occurred - External functions allowed:
read,malloc,free
- Successive calls to
get_next_line()should read the entire text file, one line at a time. - The function should return the line read followed by a newline, unless the end of the file is reached and it does not end with a newline.
- The
get_next_line.hheader file must contain at least the prototype of the function. - The
get_next_line_utils.cfile should contain any additional helper functions required forget_next_line(). - Your program must compile with the option
-D BUFFER_SIZE=nto specify the buffer size for read() calls.
For those who complete the mandatory part perfectly, you can implement the following bonuses:
- Implement
get_next_line()using a single static variable. - Allow
get_next_line()to handle multiple file descriptors simultaneously without losing track of each file descriptor's content.
Bonus files should have the suffix _bonus.[c|h] and include:
get_next_line_bonus.cget_next_line_bonus.hget_next_line_utils_bonus.c
