doc: Remove references to POSIX 202x.
[gnulib.git] / m4 / truncate.m4
blob2253644eb0e9febd882031dc0930bb091f7d40b0
1 # truncate.m4
2 # serial 7   -*- Autoconf -*-
3 dnl Copyright (C) 2017-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 AC_DEFUN([gl_FUNC_TRUNCATE],
10   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11   AC_REQUIRE([AC_CANONICAL_HOST])
13   gl_CHECK_FUNCS_ANDROID([truncate], [[#include <unistd.h>]])
14   dnl AC_CHECK_FUNC is not enough here, because when compiling for Android 4.4
15   dnl or older with _FILE_OFFSET_BITS=64, truncate() is not declared.  There
16   dnl is a function 'truncate' in libc, but it is unsuitable, because it takes
17   dnl only a 32-bit offset argument.
18   AC_CHECK_DECL([truncate], , , [[#include <unistd.h>]])
19   if test $ac_cv_have_decl_truncate = yes; then
20     m4_ifdef([gl_LARGEFILE], [
21       case "$host_os" in
22         mingw* | windows*)
23           dnl Native Windows, and Large File Support is requested.
24           dnl The mingw64 truncate64() function is based on ftruncate64(),
25           dnl which is unreliable (it may delete the file, see
26           dnl <https://web.archive.org/web/20160425005423/http://mingw-w64.sourcearchive.com/documentation/2.0-1/ftruncate64_8c_source.html>).
27           dnl Use gnulib's ftruncate() and truncate() implementation instead.
28           REPLACE_TRUNCATE=1
29           ;;
30       esac
31     ], [
32       :
33     ])
34     if test $REPLACE_TRUNCATE = 0; then
35       dnl Check for AIX 7.2 bug with trailing slash.
36       AC_CACHE_CHECK([whether truncate rejects trailing slashes],
37         [gl_cv_func_truncate_works],
38         [echo foo > conftest.tmp
39          AC_RUN_IFELSE(
40            [AC_LANG_PROGRAM(
41               [[#include <unistd.h>
42               ]],
43               [[int result = 0;
44                 if (!truncate ("conftest.tmp/", 2))
45                   result |= 1;
46                 return result;
47               ]])
48            ],
49            [gl_cv_func_truncate_works=yes],
50            [gl_cv_func_truncate_works=no],
51            [case "$host_os" in
52                                  # Guess yes on Linux systems
53                                  # and on systems that emulate the Linux system calls.
54               linux* | midipix*) gl_cv_func_truncate_works="guessing yes" ;;
55                                  # Guess yes on glibc systems.
56               *-gnu* | gnu*)     gl_cv_func_truncate_works="guessing yes" ;;
57                                  # Guess no on AIX systems.
58               aix*)              gl_cv_func_truncate_works="guessing no" ;;
59                                  # If we don't know, obey --enable-cross-guesses.
60               *)                 gl_cv_func_truncate_works="$gl_cross_guess_normal" ;;
61             esac
62            ])
63          rm -f conftest.tmp
64         ])
65       case "$gl_cv_func_truncate_works" in
66         *yes) ;;
67         *)
68            AC_DEFINE([TRUNCATE_TRAILING_SLASH_BUG], [1],
69              [Define to 1 if truncate mishandles trailing slash.])
70            REPLACE_TRUNCATE=1
71            ;;
72       esac
73     fi
74   else
75     HAVE_DECL_TRUNCATE=0
76     case "$gl_cv_onwards_func_truncate" in
77       dnl Avoid a conflict with the 'truncate' in libc.
78       yes | future*) REPLACE_TRUNCATE=1 ;;
79     esac
80   fi
83 # Prerequisites of lib/truncate.c.
84 AC_DEFUN([gl_PREREQ_TRUNCATE], [:])