[PATCH] Fix compiler warning - check return value from ftruncate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



gcc 4.3.2 has started to warn about:

gcc -o blktrace.o -c -Wall -O2 -g -W -D_GNU_SOURCE -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 blktrace.c
blktrace.c: In function â??tip_ftrunc_finalâ??:
blktrace.c:662: warning: ignoring return value of â??ftruncateâ??, declared
with attribute warn_unused_result

This simple patch overcomes that - no exit is performed as this is not
fatal, and the thread will be exitting soon enough.

Signed-off-by: Alan D. Brunelle <alan.brunelle@xxxxxx>
---
 blktrace.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/blktrace.c b/blktrace.c
index 7e27f14..ad54db5 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -654,12 +654,18 @@ static void tip_ftrunc_final(struct thread_information *tip)
 	 * truncate to right size and cleanup mmap
 	 */
 	if (tip->ofile_mmap && tip->ofile) {
+		int ret;
 		int ofd = fileno(tip->ofile);
 
 		if (tip->fs_buf)
 			munmap(tip->fs_buf, tip->fs_buf_len);
 
-		ftruncate(ofd, tip->fs_size);
+		ret = ftruncate(ofd, tip->fs_size);
+		if (ret < 0) {
+			perror(tip->fn);
+			fprintf(stderr, "Warning: thread %d ftrunc failed\n",
+				tip->cpu);
+		}
 	}
 }
 
-- 
1.5.6.3


[Index of Archives]     [Netdev]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux