[GRASS-dev] Right way to use G_getl2

Markus Metz markus.metz.giswork at gmail.com
Sat Sep 14 00:41:08 PDT 2013

Glynn Clements wrote:
> FWIW, I suggest changing the existing behaviour [of G_getl2()] so that it always
> reads an entire line, even if it can't store it all. IOW, read until
> EOL or EOF, stop storing characters once the buffer is full.

> Unlike with fgets(), which stores the line terminator in the buffer,
> there is no way for the caller of G_getl2() to determine that an
> incomplete line was read. If the buffer is too small, you lose either
> way; discarding the trailing characters is likely to be more robust
> than returning them as if they were a subsequent line (the current
> behaviour).

The caller could know if a line was only partially read if G_getl2()
would return -1 (anything but 0, 1) in case the buffer is too small.

Markus M

More information about the grass-dev mailing list