summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-02-24 20:48:54 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-02-29 15:52:52 +0100
commita014dedf92b59efd9e25e844cb08f055287c4745 (patch)
tree92f461b8bb63baf10de384d2345ea6375f24ec68
parent5be6ce8b3b15fa3771c1ad903a5bde6ffd22d31d (diff)
downloadmupdf-a014dedf92b59efd9e25e844cb08f055287c4745.tar.xz
Make fz_read_line behave like gets and return NULL at EOF.
-rw-r--r--include/mupdf/fitz/stream.h9
-rw-r--r--source/fitz/stream-read.c3
2 files changed, 10 insertions, 2 deletions
diff --git a/include/mupdf/fitz/stream.h b/include/mupdf/fitz/stream.h
index a79846ec..233e2b06 100644
--- a/include/mupdf/fitz/stream.h
+++ b/include/mupdf/fitz/stream.h
@@ -234,7 +234,14 @@ fz_stream *fz_keep_stream(fz_context *ctx, fz_stream *stm);
*/
fz_buffer *fz_read_best(fz_context *ctx, fz_stream *stm, int initial, int *truncated);
-void fz_read_line(fz_context *ctx, fz_stream *stm, char *buf, int max);
+/*
+ fz_read_line: Read a line from stream into the buffer until either a
+ terminating newline or EOF, which it replaces with a null byte ('\0').
+
+ Returns buf on success, and NULL when end of file occurs while no characters
+ have been read.
+*/
+char *fz_read_line(fz_context *ctx, fz_stream *stm, char *buf, int max);
/*
fz_available: Ask how many bytes are available immediately from
diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c
index 80091046..2ebd5ad6 100644
--- a/source/fitz/stream-read.c
+++ b/source/fitz/stream-read.c
@@ -89,7 +89,7 @@ fz_read_best(fz_context *ctx, fz_stream *stm, int initial, int *truncated)
return buf;
}
-void
+char *
fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, int n)
{
char *s = mem;
@@ -112,6 +112,7 @@ fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, int n)
}
if (n)
*s = '\0';
+ return (s == mem && c == EOF) ? NULL : mem;
}
fz_off_t