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], [
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.
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
44 if (!truncate ("conftest.tmp/", 2))
49 [gl_cv_func_truncate_works=yes],
50 [gl_cv_func_truncate_works=no],
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" ;;
65 case "$gl_cv_func_truncate_works" in
68 AC_DEFINE([TRUNCATE_TRAILING_SLASH_BUG], [1],
69 [Define to 1 if truncate mishandles trailing slash.])
76 case "$gl_cv_onwards_func_truncate" in
77 dnl Avoid a conflict with the 'truncate' in libc.
78 yes | future*) REPLACE_TRUNCATE=1 ;;
83 # Prerequisites of lib/truncate.c.
84 AC_DEFUN([gl_PREREQ_TRUNCATE], [:])