rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit b048d96e41932714c689a164f36c79ebb2a5933d
parent 9673951c40cfefd07d15bac13bc7ad26f5d30411
Author: vaplv <vaplv@free.fr>
Date:   Thu, 13 Feb 2020 11:59:13 +0100

Minor fix of the txtrdr_read_line function

Check if an error occurs if nothing can be read. Up to now, the function
assumes that nothing was read only when the end of file was reached.

Diffstat:
Msrc/test_text_reader.c | 1+
Msrc/text_reader.c | 9+++++++--
Msrc/text_reader.h | 6+++++-
3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/test_text_reader.c b/src/test_text_reader.c @@ -58,6 +58,7 @@ check_text_reader(struct txtrdr* txtrdr) CHK(txtrdr_get_line(txtrdr) == NULL); CHK(txtrdr_get_line_num(txtrdr) == nlines); CHK(txtrdr_read_line(txtrdr) == RES_OK); + CHK(txtrdr_get_line(txtrdr) == NULL); txtrdr_set_line_num(txtrdr, nlines/2); CHK(txtrdr_get_line_num(txtrdr) == nlines/2); } diff --git a/src/text_reader.c b/src/text_reader.c @@ -163,8 +163,13 @@ txtrdr_read_line(struct txtrdr* txtrdr) (int)darray_char_size_get(&txtrdr->line), txtrdr->stream); if(!str) { - darray_char_clear(&txtrdr->line); - break; + if(ferror(txtrdr->stream)) { + res = RES_IO_ERR; + goto error; + } else { + darray_char_clear(&txtrdr->line); + break; + } } /* Ensure tht the whole line is read */ diff --git a/src/text_reader.h b/src/text_reader.h @@ -47,7 +47,11 @@ txtrdr_ref_put (struct txtrdr* txtrdr); /* Read a non empty line, i.e. line with text that is not a comment. The new - * line character as well as the comments are skipped from the reading */ + * line character as well as the comments are skipped from the reading. A + * returned value different of RES_OK means than an error occurs while reading + * the stream. Note that reaching the end of file is not an error and thus that + * no error is returned if the end of file is reached, even though nothing was + * read. In this case the returned line is simply NULL. */ RSYS_API res_T txtrdr_read_line (struct txtrdr* txtrdr);