From f972da18c85ebeb8591f585e7480fae9c1c5c380 Mon Sep 17 00:00:00 2001 From: oetiker Date: Thu, 6 Sep 2007 08:40:36 +0000 Subject: [PATCH] rrd_open.c (rrd_read): Mimicing read() behaviour for EOF case and NULL buffer case. -- Bernhard Fischer git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1197 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_open.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rrd_open.c b/src/rrd_open.c index 0774bce..c6a2d7d 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -440,8 +440,13 @@ inline ssize_t rrd_read( { #ifdef HAVE_MMAP size_t _cnt = count; - ssize_t _surplus = rrd_file->pos + _cnt - rrd_file->file_len; + ssize_t _surplus; + if (rrd_file->pos > rrd_file->file_len || _cnt == 0) /* EOF */ + return 0; + if (buf == NULL) + return -1; /* EINVAL */ + _surplus = rrd_file->pos + _cnt - rrd_file->file_len; if (_surplus > 0) { /* short read */ _cnt -= _surplus; } -- 2.30.2