SDL: Haiku does not have fdatasync, but has fsync

From b3388d5753705de3c6f580fe7497a12050835206 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 28 Sep 2024 18:08:36 +0200
Subject: [PATCH] Haiku does not have fdatasync, but has fsync

https://dev.haiku-os.org/ticket/17378
---
 src/file/SDL_iostream.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/file/SDL_iostream.c b/src/file/SDL_iostream.c
index 3622e9290c126..7fff91e1695e6 100644
--- a/src/file/SDL_iostream.c
+++ b/src/file/SDL_iostream.c
@@ -488,8 +488,16 @@ static bool SDLCALL stdio_flush(void *userdata, SDL_IOStatus *status)
     }
     #elif defined(_POSIX_SYNCHRONIZED_IO)  // POSIX defines this if fdatasync() exists, so we don't need a CMake test.
         #ifndef SDL_PLATFORM_RISCOS  // !!! FIXME: however, RISCOS doesn't have the symbol...maybe we need to link to an extra library or something?
-        if (iodata->regular_file && (fdatasync(fileno(iodata->fp)) == -1)) {
-            return SDL_SetError("Error flushing datastream: %s", strerror(errno));
+        if (iodata->regular_file) {
+            int sync_result;
+#ifdef SDL_PLATFORM_HAIKU
+            sync_result = fsync(fileno(iodata->fp));
+#else
+            sync_result = fdatasync(fileno(iodata->fp));
+#endif
+            if (sync_result == -1) {
+                return SDL_SetError("Error flushing datastream: %s", strerror(errno));
+            }
         }
         #endif
     #endif