Code

fix rrd_write -- Bernhard Fischer
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 30 May 2007 19:56:34 +0000 (19:56 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 30 May 2007 19:56:34 +0000 (19:56 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1094 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/src/rrd_open.c
program/src/rrd_update.c

index 238c052ae3e168f50d5251c47402dd7cc07fc935..92369fd01c094bb560e77f6ad7d64f388059a04b 100644 (file)
@@ -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
 }
 
index 18db8e7ceb02c5e0cba86f12aa9bb6bc330e8ba8..b114c9bfa61fa87a1e34488c465a8dd8386311e4 100644 (file)
@@ -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;
         }