Skip to contentSkip to conversation

Fix compiler warning - check return value from ftruncate

PATCH New Alan D. Brunelle 1 participant 1 message Nov 12, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix compiler warning - check return value from ftruncate

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.

---
 blktrace.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
blktrace.c +7 -1
index 7e27f14..ad54db5 100644
@@ -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);
+		}
 	}
 }
 
Signature · 1 line
1.5.6.3