int get_next_line(int fd, char **line);
This is a usable function. It presumably allocates a character array of tentatively sufficient size, reads a line into it, reallocates and reads the remainder if necessary, and then passes the allocated string back by assigning it to the dereferenced second argument (*line = allocated_string;
).
int get_next_line(int fd, char *line);
This is patent nonsense. There is no way to write get_next_line
that is remotely as usable as the previous one. It cannot determine the size of the character array passed to it, nor can it reallocate this array. The only way to specify this function to behave somewhat sensibly is to demand that the argument must be an array of some pre-determined size specified elsewhere. This could only be useful in some pretty narrow contexts.
Note that this is not an immediately obvious observation. The C language used to have gets
up until 2011. Programmers used to be rather careless back when.
int get_next_line(int fd, char *line, size_t size);
This could be a somewhat useful function. It could work almost like the standard read
function, except it wouldn't read past the first end-of-line character. (Or like fgets
for Posix fike handles.) Of course users need to deal with the case of the input line being longer than their array. Presumably get_next_line
would return the number if scanned characters.
Note const int
is useless in function prototypes. All standard functions specify int
in such cases.