[stgt] [PATCH] usr/tgtimg.c: use `ftruncate` to fix build with uClibc

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Mon Jan 17 04:40:53 CET 2011


On Sun, 16 Jan 2011 13:41:31 +0100
Paul Menzel <paulepanter at users.sourceforge.net> wrote:

> From: Khem Raj <raj.khem at gmail.com>
> Date: Sat Jan 15 16:37:19 2011 -0800
> 
> uClibc does not provide `posix_fallocate` so use `ftruncate`.

Hmm, what posix_fallocate does is identical to what ftruncate does in
this situation?

We avoid to adding #ifdef to *.c like linux kernel coding
style. Please add #ifdef to *.h instead.

You can do something like this:

diff --git a/usr/tgtimg.c b/usr/tgtimg.c
index 169207a..8ca2a4d 100644
--- a/usr/tgtimg.c
+++ b/usr/tgtimg.c
@@ -38,6 +38,7 @@
 #include "ssc.h"
 #include "libssc.h"
 #include "scsi.h"
+#include "util.h"
 
 #define NO_LOGGING
 #include "log.h"
@@ -438,7 +439,7 @@ static int sbc_new(int op, char *path, char *capacity, char *media_type)
 			perror("Failed creating file");
 			exit(2);
 		}
-		if (posix_fallocate(fd, 0, size*1024*1024LL) == -1) {
+		if (__fallocate(fd, 0, size*1024*1024LL) == -1) {
 			perror("posix_fallocate failed.");
 			exit(3);
 		}
diff --git a/usr/util.h b/usr/util.h
index 9530d2a..4a0e303 100644
--- a/usr/util.h
+++ b/usr/util.h
@@ -159,4 +159,16 @@ struct signalfd_siginfo {
 };
 #endif
 
+#ifndef __UCLIBC__
+static inline int __fallocate(int fd, off_t offset, off_t len)
+{
+	return posix_fallocate(fd, offset, len);
+}
+#else
+static inline int __fallocate(int fd, off_t offset, off_t len)
+{
+	return 0
+}
+#endif
+
 #endif
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list