configury: move autoconf macros to build-aux subdirectory.
[m4/ericb.git] / build-aux / m4 / m4-rename.m4
blob4062cdec2ffdfd9e9de333c82565d0bb841e4e04
1 #                                                            -*- Autoconf -*-
2 # m4-rename.m4 -- Test the abilities of rename.
3 # Written by Eric Blake <ebb9@byu.net>
5 # Copyright (C) 2008, 2010, 2013 Free Software Foundation, Inc.
7 # This file is part of GNU M4.
9 # GNU M4 is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # GNU M4 is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 # serial 1
24 # M4_RENAME
25 # ---------
26 # Detect platforms like mingw where rename can't move open files.
27 AC_DEFUN([M4_RENAME],
28 [AC_CACHE_CHECK([whether an open file can be renamed],
29   [M4_cv_func_rename_open_file_works],
30   [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
31       [FILE *f = fopen ("conftest.1", "w+");
32        int result = rename ("conftest.1", "conftest.2");
33        fclose (f); remove ("conftest.1"); remove ("conftest.2");
34        return result;])],
35     [M4_cv_func_rename_open_file_works=yes],
36     [M4_cv_func_rename_open_file_works=no],
37     [M4_cv_func_rename_open_file_works='guessing no'])])
38 if test "$M4_cv_func_rename_open_file_works" = yes ; then
39   M4_rename_open_works=1
40 else
41   M4_rename_open_works=0
43 AC_DEFINE_UNQUOTED([RENAME_OPEN_FILE_WORKS], [$M4_rename_open_works],
44   [Define to 1 if a file can be renamed while open, or to 0 if not.])