From 276e13197ae5a9056ce48a91f04571057a7fcc39 Mon Sep 17 00:00:00 2001 From: oetiker Date: Wed, 30 May 2007 19:56:34 +0000 Subject: [PATCH] fix rrd_write -- Bernhard Fischer git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1094 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_open.c | 20 ++++++++++++-------- program/src/rrd_update.c | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/program/src/rrd_open.c b/program/src/rrd_open.c index 238c052a..92369fd0 100644 --- a/program/src/rrd_open.c +++ b/program/src/rrd_open.c @@ -400,19 +400,19 @@ int rrd_close( #endif /* DEBUG */ #ifdef USE_MADVISE -#ifdef ONE_PAGE +# ifdef ONE_PAGE /* Keep headers around, round up to next page boundary. */ ret = PAGE_ALIGN(rrd_file->header_len % _page_size + rrd_file->header_len); if (rrd_file->file_len > ret) _madvise(rrd_file->file_start + ret, rrd_file->file_len - ret, MADV_DONTNEED); -#else +# else /* ignoring errors from RRDs that are smaller then the file_len+rounding */ _madvise(rrd_file->file_start + PAGE_ALIGN_DOWN(rrd_file->header_len), rrd_file->file_len - PAGE_ALIGN(rrd_file->header_len), MADV_DONTNEED); -#endif +# endif #endif #ifdef HAVE_MMAP ret = munmap(rrd_file->file_start, rrd_file->file_len); @@ -467,13 +467,13 @@ inline off_t rrd_tell( /* read count bytes into buffer buf, starting at rrd_file->pos. * Returns the number of bytes read. */ -ssize_t rrd_read( +inline ssize_t rrd_read( rrd_file_t *rrd_file, void *buf, size_t count) { #ifdef HAVE_MMAP - buf = memmove(buf, rrd_file->file_start + rrd_file->pos, count); + buf = memcpy(buf, rrd_file->file_start + rrd_file->pos, count); rrd_file->pos += count; /* mimmic read() semantics */ return count; #else @@ -491,16 +491,20 @@ ssize_t rrd_read( * rrd_file->pos of rrd_file->fd. * Returns the number of bytes written. */ -ssize_t rrd_write( +inline ssize_t rrd_write( rrd_file_t *rrd_file, const void *buf, size_t count) { #ifdef HAVE_MMAP - memmove(rrd_file->file_start + rrd_file->pos, buf, count); + memcpy(rrd_file->file_start + rrd_file->pos, buf, count); + rrd_file->pos += count; return count; /* mimmic write() semantics */ #else - return write(rrd_file->fd, buf, count); + ssize_t _sz = write(rrd_file->fd, buf, count); + if (_sz > 0) + rrd_file->pos += _sz; + return _sz; #endif } diff --git a/program/src/rrd_update.c b/program/src/rrd_update.c index 18db8e7c..b114c9bf 100644 --- a/program/src/rrd_update.c +++ b/program/src/rrd_update.c @@ -68,7 +68,7 @@ static inline void normalize_time( } } -static info_t *write_RRA_row( +static inline info_t *write_RRA_row( rrd_file_t *rrd_file, rrd_t *rrd, unsigned long rra_idx, @@ -104,7 +104,7 @@ static info_t *write_RRA_row( if (rrd_write (rrd_file, &(rrd->cdp_prep[cdp_idx].scratch[CDP_scratch_idx].u_val), - sizeof(rrd_value_t) * 1) != sizeof(rrd_value_t) * 1) { + sizeof(rrd_value_t)) != sizeof(rrd_value_t)) { rrd_set_error("writing rrd: %s", rrd_strerror(errno)); return 0; } -- 2.30.2