From: oetiker Date: Thu, 6 Sep 2007 08:40:36 +0000 (+0000) Subject: rrd_open.c (rrd_read): Mimicing read() behaviour for EOF case and NULL buffer case. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=89048b0ba185bb18cceedf498274b135750a2c0a;p=rrdtool-all.git 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@1197 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/src/rrd_open.c b/program/src/rrd_open.c index 0774bced..c6a2d7d9 100644 --- a/program/src/rrd_open.c +++ b/program/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; }