This is an automated email from the ASF dual-hosted git repository.
yong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 5154149936 [fix]compile error of the file native_io_jni.c for the env
jdk11 & windows (#4665)
5154149936 is described below
commit 5154149936e3f8187ae9e2755f43ea9c0ecb866e
Author: fengyubiao <[email protected]>
AuthorDate: Wed Oct 22 12:53:14 2025 +0800
[fix]compile error of the file native_io_jni.c for the env jdk11 & windows
(#4665)
Co-authored-by: fengyubiao <[email protected]>
---
native-io/src/main/native-io-jni/cpp/native_io_jni.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/native-io/src/main/native-io-jni/cpp/native_io_jni.c
b/native-io/src/main/native-io-jni/cpp/native_io_jni.c
index d3bc164bec..7be468518b 100644
--- a/native-io/src/main/native-io-jni/cpp/native_io_jni.c
+++ b/native-io/src/main/native-io-jni/cpp/native_io_jni.c
@@ -20,11 +20,16 @@
*/
#define _GNU_SOURCE
+#include <jni.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
+#ifdef _WIN32
+#include <io.h>
+#else
#include <unistd.h>
+#endif
#include <org_apache_bookkeeper_common_util_nativeio_NativeIOJni.h>
@@ -165,7 +170,14 @@ JNIEXPORT jint JNICALL
Java_org_apache_bookkeeper_common_util_nativeio_NativeIOJni_fsync(JNIEnv * env,
jclass clazz,
jint fd) {
- int res = fsync(fd);
+ int res;
+
+ // Guarantee compatibility for winsows.
+ #ifdef _WIN32
+ res = _commit((int)fd);
+ #else
+ res = fsync((int)fd);
+ #endif
if (res == -1) {
throwExceptionWithErrno(env, "Failed to fsync");