rename: fix cygwin 1.5.x bugs
[gnulib.git] / m4 / rename.m4
1 # serial 18
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
21   dnl Solaris 10 mistakenly allows rename("file","name/").
22   dnl This particular condition can be worked around without stripping
23   dnl trailing slash.
24   AC_CACHE_CHECK([whether rename honors trailing slash on destination],
25     [gl_cv_func_rename_slash_dst_works],
26     [rm -rf conftest.f conftest.f1
27     touch conftest.f ||
28       AC_MSG_ERROR([cannot create temporary files])
29     AC_RUN_IFELSE([AC_LANG_PROGRAM([[
30 #       include <stdio.h>
31 #       include <stdlib.h>
32 ]], [return !rename ("conftest.f", "conftest.f1/");])],
33       [gl_cv_func_rename_slash_dst_works=yes],
34       [gl_cv_func_rename_slash_dst_works=no],
35       dnl When crosscompiling, assume rename is broken.
36       [gl_cv_func_rename_slash_dst_works="guessing no"])
37     rm -rf conftest.f conftest.f1
38   ])
39   if test "x$gl_cv_func_rename_slash_dst_works" != xyes; then
40     AC_LIBOBJ([rename])
41     REPLACE_RENAME=1
42     AC_DEFINE([RENAME_TRAILING_SLASH_DEST_BUG], [1],
43       [Define if rename does not correctly handle slashes on the destination
44        argument, such as on Solaris 10.])
45   fi
46
47   dnl SunOS 4.1.1_U1 mistakenly forbids rename("dir/","name").
48   dnl Solaris 9 mistakenly allows rename("file/","name").
49   dnl These bugs require stripping trailing slash to avoid corrupting
50   dnl symlinks with a trailing slash.
51   AC_CACHE_CHECK([whether rename honors trailing slash on source],
52     [gl_cv_func_rename_slash_src_works],
53     [rm -rf conftest.f conftest.d1 conftest.d2
54     touch conftest.f && mkdir conftest.d1 ||
55       AC_MSG_ERROR([cannot create temporary files])
56     AC_RUN_IFELSE([AC_LANG_PROGRAM([[
57 #       include <stdio.h>
58 #       include <stdlib.h>
59 ]], [if (rename ("conftest.f/", "conftest.d2") == 0) return 1;
60      if (rename ("conftest.d1/", "conftest.d2") != 0) return 2;])],
61       [gl_cv_func_rename_slash_src_works=yes],
62       [gl_cv_func_rename_slash_src_works=no],
63       dnl When crosscompiling, assume rename is broken.
64       [gl_cv_func_rename_slash_src_works="guessing no"])
65     rm -rf conftest.f conftest.d1 conftest.d2
66   ])
67   if test "x$gl_cv_func_rename_slash_src_works" != xyes; then
68     AC_LIBOBJ([rename])
69     REPLACE_RENAME=1
70     AC_DEFINE([RENAME_TRAILING_SLASH_SOURCE_BUG], [1],
71       [Define if rename does not correctly handle slashes on the source
72        argument, such as on Solaris 9 or cygwin 1.5.])
73   fi
74
75   dnl Cygwin 1.5.x mistakenly allows rename("dir","file").
76   dnl mingw mistakenly forbids rename("dir1","dir2").
77   dnl These bugs require stripping trailing slash to avoid corrupting
78   dnl symlinks with a trailing slash.
79   AC_CACHE_CHECK([whether rename manages existing destinations correctly],
80     [gl_cv_func_rename_dest_works],
81     [rm -rf conftest.f conftest.d1 conftest.d2
82     touch conftest.f && mkdir conftest.d1 conftest.d2 ||
83       AC_MSG_ERROR([cannot create temporary files])
84     AC_RUN_IFELSE([AC_LANG_PROGRAM([[
85 #       include <stdio.h>
86 #       include <stdlib.h>
87 ]], [if (rename ("conftest.d1", "conftest.d2") != 0) return 1;
88      if (rename ("conftest.d2", "conftest.f") == 0) return 2;])],
89       [gl_cv_func_rename_dest_works=yes],
90       [gl_cv_func_rename_dest_works=no],
91       dnl When crosscompiling, assume rename is broken.
92       [gl_cv_func_rename_dest_works="guessing no"])
93     rm -rf conftest.f conftest.f1 conftest.d1 conftest.d2
94   ])
95   if test "x$gl_cv_func_rename_dest_works" != xyes; then
96     AC_LIBOBJ([rename])
97     REPLACE_RENAME=1
98     AC_DEFINE([RENAME_DEST_EXISTS_BUG], [1],
99       [Define if rename does not work when the destination file exists,
100        as on Windows.])
101   fi
102 ])