[PATCH] win32: Add ftruncate function detection

Tianlan Zhou posted 1 patch 4 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260108180315.1587-1-bobby825@126.com
Maintainers: Stefan Weil <sw@weilnetz.de>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
include/system/os-win32.h |  2 +-
meson.build               | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
[PATCH] win32: Add ftruncate function detection
Posted by Tianlan Zhou 4 weeks, 1 day ago
Add detection for `ftruncate` function in Meson, so that it can be
used when possible instead of fallback version `qemu_ftruncate64`.

Signed-off-by: Tianlan Zhou <bobby825@126.com>
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(-)

diff --git a/include/system/os-win32.h b/include/system/os-win32.h
index 22d72babdf..9832b7589a 100644
--- a/include/system/os-win32.h
+++ b/include/system/os-win32.h
@@ -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
 
diff --git a/meson.build b/meson.build
index db87358d62..0b41952a0b 100644
--- a/meson.build
+++ b/meson.build
@@ -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 #
 ########################
-- 
2.52.0