[lttng-dev] [Babeltrace PATCH 15/23] Add MinGW implementation of posix_fallocate

Ikaheimonen, JP jp_ikaheimonen at mentor.com
Wed May 22 04:07:10 EDT 2013


Add MinGW implementation of posix_fallocate.
The implementation is in a new source file (compat_fcntl.c).
Add the new source file to the build.
---
 compat/Makefile.am                |  2 +-
 compat/compat_fcntl.c             | 23 +++++++++++++++++++++++
 formats/ctf/ctf.c                 |  2 +-
 include/babeltrace/compat/fcntl.h | 11 +++++++++++
 4 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 compat/compat_fcntl.c
 create mode 100644 include/babeltrace/compat/fcntl.h

diff --git a/compat/Makefile.am b/compat/Makefile.am
index 16dd2e9..03b3daf 100644
--- a/compat/Makefile.am
+++ b/compat/Makefile.am
@@ -8,5 +8,5 @@ libcompat_la_LDFLAGS = \
 	-Wl,--no-as-needed
 
 if BABELTRACE_BUILD_WITH_MINGW
-libcompat_la_SOURCES += compat_mman.c compat_uuid.c compat_stdlib.c
+libcompat_la_SOURCES += compat_mman.c compat_uuid.c compat_stdlib.c compat_fcntl.c
 endif
diff --git a/compat/compat_fcntl.c b/compat/compat_fcntl.c
new file mode 100644
index 0000000..3fd23a9
--- /dev/null
+++ b/compat/compat_fcntl.c
@@ -0,0 +1,23 @@
+/* This file is only built under MINGW32 */
+
+#include <windows.h>
+#include <fcntl.h>
+
+int posix_fallocate(int fd, off_t offset, off_t len)
+{
+	HANDLE handle;
+	LARGE_INTEGER current_pos;
+	LARGE_INTEGER pos;
+	BOOL ret;
+
+	handle = (HANDLE) _get_osfhandle(fd);
+	pos.QuadPart = 0;
+	SetFilePointerEx(handle, pos, &current_pos, FILE_CURRENT);
+	pos.QuadPart = (__int64)offset + (__int64)len;
+	SetFilePointerEx(handle, pos, NULL, FILE_BEGIN);
+	ret = SetEndOfFile(handle);
+	SetFilePointerEx(handle, current_pos, NULL, FILE_BEGIN);
+	if (ret == 0)
+		return -1;
+	return 0;
+}
diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
index b476a29..0db23c3 100644
--- a/formats/ctf/ctf.c
+++ b/formats/ctf/ctf.c
@@ -41,7 +41,7 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
+#include <babeltrace/compat/fcntl.h>
 #include <dirent.h>
 #include <glib.h>
 #include <babeltrace/compat/unistd.h>
diff --git a/include/babeltrace/compat/fcntl.h b/include/babeltrace/compat/fcntl.h
new file mode 100644
index 0000000..9fc7539
--- /dev/null
+++ b/include/babeltrace/compat/fcntl.h
@@ -0,0 +1,11 @@
+#ifndef _BABELTRACE_INCLUDE_COMPAT_FCNTL_H
+#define _BABELTRACE_INCLUDE_COMPAT_FCNTL_H
+
+#include <fcntl.h>
+#ifdef __MINGW32__
+
+int posix_fallocate(int fd, off_t offset, off_t len);
+
+#endif
+
+#endif
-- 
1.8.1.msysgit.1




More information about the lttng-dev mailing list