rename: modernize replacement
[gnulib.git] / m4 / rename.m4
1 # serial 15
2
3 # Copyright (C) 2001, 2003, 2005, 2006, 2009 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 dnl From Volker Borchert.
9 dnl Determine whether rename works for source file names with a trailing slash.
10 dnl The rename from SunOS 4.1.1_U1 doesn't.
11 dnl
12 dnl If it doesn't, then define RENAME_TRAILING_SLASH_BUG and arrange
13 dnl to compile the wrapper function.
14 dnl
15
16 AC_DEFUN([gl_FUNC_RENAME],
17 [
18   AC_REQUIRE([AC_CANONICAL_HOST])
19   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
20   AC_CACHE_CHECK([whether rename is broken with a trailing slash],
21   gl_cv_func_rename_trailing_slash_bug,
22   [
23     rm -rf conftest.d1 conftest.d2
24     mkdir conftest.d1 ||
25       AC_MSG_ERROR([cannot create temporary directory])
26     AC_RUN_IFELSE([AC_LANG_SOURCE([[
27 #       include <stdio.h>
28 #       include <stdlib.h>
29         int
30         main ()
31         {
32           exit (rename ("conftest.d1/", "conftest.d2") ? 1 : 0);
33         }
34       ]])],
35       [gl_cv_func_rename_trailing_slash_bug=no],
36       [gl_cv_func_rename_trailing_slash_bug=yes],
37       dnl When crosscompiling, assume rename is broken.
38       [gl_cv_func_rename_trailing_slash_bug=yes])
39
40       rm -rf conftest.d1 conftest.d2
41   ])
42  AC_CACHE_CHECK([whether rename is broken when the destination exists],
43   gl_cv_func_rename_dest_exists_bug,
44   [
45     case "$host_os" in
46       mingw*) gl_cv_func_rename_dest_exists_bug=yes ;;
47       *) gl_cv_func_rename_dest_exists_bug=no ;;
48     esac
49   ])
50   if test $gl_cv_func_rename_trailing_slash_bug = yes ||
51      test $gl_cv_func_rename_dest_exists_bug = yes; then
52     AC_LIBOBJ([rename])
53     REPLACE_RENAME=1
54     if test $gl_cv_func_rename_trailing_slash_bug = yes; then
55       AC_DEFINE([RENAME_TRAILING_SLASH_BUG], [1],
56         [Define if rename does not work for source file names with a trailing
57          slash, like the one from SunOS 4.1.1_U1.])
58     fi
59     if test $gl_cv_func_rename_dest_exists_bug = yes; then
60       AC_DEFINE([RENAME_DEST_EXISTS_BUG], [1],
61         [Define if rename does not work when the destination file exists,
62          as on Windows.])
63     fi
64     gl_PREREQ_RENAME
65   fi
66 ])
67
68 # Prerequisites of lib/rename.c.
69 AC_DEFUN([gl_PREREQ_RENAME], [:])