>> On GNU systems, getline and getdelim rock more than fgets, because of not
>> requiring to specify a buffer size in advance.
>> --
>But that's the very reason you should be using them. Because you *can* specify
>a size. If getline() don't know how big the buffer is, what keeps them from
>writing junk all over the memory? What happens if the user falls asleep on the
>keyboard?
From the GNU libc documentation:
Before calling getline, you should place in *lineptr the address of a
buffer *n bytes long, allocated with malloc. If this buffer is long
enough to hold the line, getline stores the line in this buffer.
Otherwise, getline makes the buffer bigger using realloc, storing the new
buffer address back in *lineptr and the increased size back in *n. See
section Unconstrained Allocation.
If you set *lineptr to a null pointer, and *n to zero, before the call,
then getline allocates the initial buffer for you by calling malloc.
In either case, when getline returns, *lineptr is a char * which points
to the text of the line.
When getline is successful, it returns the number of characters read
(including the newline, but not including the terminating null). This
value enables you to distinguish null characters that are part of the
line from the null character inserted as a terminator.
This function is one reason why many GNU programs don't have hard-coded
limits on input line length.
--
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.