Avoid some possibly wrong configure test results.
[gnulib.git] / m4 / ftruncate.m4
blob0ecc0b3e4053dcf9c86c741944d1ee7400a73e58
1 # ftruncate.m4
2 # serial 24
3 dnl Copyright (C) 2000-2001, 2003-2007, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # See if we need to emulate a missing ftruncate function using _chsize.
10 AC_DEFUN([gl_FUNC_FTRUNCATE],
12   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
13   gl_CHECK_FUNCS_ANDROID([ftruncate], [[#include <unistd.h>]])
14   if test $ac_cv_func_ftruncate = yes; then
15     m4_ifdef([gl_LARGEFILE], [
16       AC_REQUIRE([AC_CANONICAL_HOST])
17       case "$host_os" in
18         mingw* | windows*)
19           dnl Native Windows, and Large File Support is requested.
20           dnl The MSVCRT _chsize() function only accepts a 32-bit file size,
21           dnl and the mingw64 ftruncate64() function is unreliable (it may
22           dnl delete the file, see
23           dnl <https://web.archive.org/web/20160425005423/http://mingw-w64.sourcearchive.com/documentation/2.0-1/ftruncate64_8c_source.html>).
24           dnl Use gnulib's ftruncate() implementation instead.
25           REPLACE_FTRUNCATE=1
26           ;;
27       esac
28     ], [
29       :
30     ])
31   else
32     HAVE_FTRUNCATE=0
33     case "$gl_cv_onwards_func_ftruncate" in
34       future*) REPLACE_FTRUNCATE=1 ;;
35     esac
36   fi
39 # Prerequisites of lib/ftruncate.c.
40 AC_DEFUN([gl_PREREQ_FTRUNCATE],
42   AC_CHECK_FUNCS([_chsize])