Skip to contentSkip to conversation

win32: Add ftruncate function detection

PATCH New Tianlan Zhou 1 participant 1 message Jan 8 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 win32: Add ftruncate function detection

Add detection for ftruncate function in Meson, so that it can be used when possible instead of fallback version qemu_ftruncate64.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3234

---
 include/system/os-win32.h |  2 +-
 meson.build               | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
include/system/os-win32.h +1 -1
index 22d72babdf..9832b7589a 100644
@@ -140,7 +140,7 @@ static inline void os_setup_limits(void)
 
 int qemu_ftruncate64(int, int64_t);
 
-#if !defined(ftruncate)
+#ifndef CONFIG_FTRUNCATE
 # define ftruncate qemu_ftruncate64
 #endif
 
meson.build +11 -0
index db87358d62..0b41952a0b 100644
@@ -3253,6 +3253,17 @@ if host_os == 'windows'
   config_host_data.set('CONFIG_CONVERT_STRING_TO_BSTR', has_convert_string_to_bstr)
 endif
 
+# Detect if ftruncate exist
+if host_os == 'windows'
+  has_ftruncate = cxx.links('''
+    #include <unistd.h>
+    int main() {
+        return ftruncate(0, 0);
+    }
+  ''')
+  config_host_data.set('CONFIG_FTRUNCATE', has_ftruncate)
+endif
+
 ########################
 # Target configuration #
 ########################
Signature · 1 line
2.52.0