Skip to content

Commit 5154149

Browse files
poorbarcodefengyubiao
andauthored
[fix]compile error of the file native_io_jni.c for the env jdk11 & windows (#4665)
Co-authored-by: fengyubiao <[email protected]>
1 parent bde9ff2 commit 5154149

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

native-io/src/main/native-io-jni/cpp/native_io_jni.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@
2020
*/
2121
#define _GNU_SOURCE
2222

23+
#include <jni.h>
2324
#include <errno.h>
2425
#include <fcntl.h>
2526
#include <stdlib.h>
2627
#include <string.h>
28+
#ifdef _WIN32
29+
#include <io.h>
30+
#else
2731
#include <unistd.h>
32+
#endif
2833

2934
#include <org_apache_bookkeeper_common_util_nativeio_NativeIOJni.h>
3035

@@ -165,7 +170,14 @@ JNIEXPORT jint JNICALL
165170
Java_org_apache_bookkeeper_common_util_nativeio_NativeIOJni_fsync(JNIEnv * env,
166171
jclass clazz,
167172
jint fd) {
168-
int res = fsync(fd);
173+
int res;
174+
175+
// Guarantee compatibility for winsows.
176+
#ifdef _WIN32
177+
res = _commit((int)fd);
178+
#else
179+
res = fsync((int)fd);
180+
#endif
169181

170182
if (res == -1) {
171183
throwExceptionWithErrno(env, "Failed to fsync");

0 commit comments

Comments
 (0)