Creating readline() function, reading from a file descriptor
As we've basically worked out in the comments: when there's already a thing, use the thing. To get a line from a file descriptor, you can


Call fdopen on your file descriptor to get a FILE*
Check for NULL, perror and exit if necessary
Call fgets
Check for NULL again
Repeat 3-4 as necessary
fclose your FILE*
Do not call close on your file descriptor