]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Emulate fsync on mingw (#1650)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Thu, 25 Jan 2024 13:48:35 +0000 (13:48 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sat, 27 Jan 2024 17:39:09 +0000 (17:39 +0000)
MS Windows (and mingw) do not offer fsync(),
but they offer the API-compatible _commit().

compat/os/mingw.h
configure.ac

index 6abd702db867b3ef9aa87a56e66d9ce5da49c050..6a0d2a86496692b5984c10bb7db1739709cbd7ea 100644 (file)
 #include <windows.h>
 #endif
 
+// needed for _commmit and _get_osfhandle
+#if HAVE_IO_H
+#include <io.h>
+#endif
+
+#if !HAVE_FSYNC
+// _commit(fd) is API-compatible with fsync(fd) and has equivalent behaviour
+inline int
+fsync(int fd)
+{
+    return _commit(fd);
+}
+#endif
+
 #endif /* _SQUID_MINGW_*/
 #endif /* SQUID_OS_MINGW_H */
index 57c5cdafc6fc59b751337f01055d40b0100c36a1..de6bc5e5acc43c613c40247180c5e509ae71b9f4 100644 (file)
@@ -191,7 +191,7 @@ AS_CASE(["$squid_host_os"],
     CXXFLAGS="$CXXFLAGS -mthreads -static-libgcc -static-libstdc++"
     dnl Check for Winsock only on MinGW
     SQUID_CHECK_WINSOCK_LIB
-    AC_CHECK_HEADERS([ws2tcpip.h winsock2.h windows.h],,,[
+    AC_CHECK_HEADERS([ws2tcpip.h winsock2.h windows.h io.h],,,[
 #if HAVE_WS2TCPIP_H
 #include <ws2tcpip.h>
 #endif
@@ -204,6 +204,7 @@ AS_CASE(["$squid_host_os"],
     ])
     MINGW_LIBS="-lmingwex"
     AC_SUBST(MINGW_LIBS)
+    AC_CHECK_FUNCS([fsync])
   ],
 
   [freebsd],[