perf-counter: fix compiler warnings
authorAndy Zhou <azhou@nicira.com>
Tue, 14 Apr 2015 21:22:08 +0000 (14:22 -0700)
committerAndy Zhou <azhou@nicira.com>
Tue, 14 Apr 2015 22:23:02 +0000 (15:23 -0700)
Gcc complains about:
lib/perf-counter.c:43:13: error: ignoring return value of 'read',
declared with attribute warn_unused_result [-Werror=unused-result]
         read(fd__, counter, sizeof(*counter));

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Russell Bryant <rbryant@redhat.com>
lib/perf-counter.c

index 7bd7834..b700e49 100644 (file)
@@ -39,9 +39,9 @@ static int fd__ = 0;
 uint64_t
 perf_counter_read(uint64_t *counter)
 {
-    if (fd__ > 0) {
-        read(fd__, counter, sizeof(*counter));
-    } else {
+    size_t size = sizeof *counter;
+
+    if (fd__ <= 0 || read(fd__, counter, size) < size) {
         *counter = 0;
     }