3 # Copyright (C) 2001, 2003, 2005-2006, 2009-2010 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.
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.
12 dnl If it doesn't, then define RENAME_TRAILING_SLASH_BUG and arrange
13 dnl to compile the wrapper function.
16 AC_DEFUN([gl_FUNC_RENAME],
18 AC_REQUIRE([AC_CANONICAL_HOST])
19 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
20 AC_CHECK_FUNCS_ONCE([lstat])
22 dnl Solaris 10 mistakenly allows rename("file","name/").
23 dnl NetBSD 1.6 mistakenly forbids rename("dir","name/").
24 dnl FreeBSD 7.2 mistakenly allows rename("file","link-to-file/").
25 dnl The Solaris bug can be worked around without stripping
26 dnl trailing slash, while the NetBSD bug requires stripping;
27 dnl the two conditions can be distinguished by whether hard
28 dnl links are also broken.
29 AC_CACHE_CHECK([whether rename honors trailing slash on destination],
30 [gl_cv_func_rename_slash_dst_works],
31 [rm -rf conftest.f conftest.f1 conftest.d1 conftest.d2 conftest.lnk
32 touch conftest.f && mkdir conftest.d1 ||
33 AC_MSG_ERROR([cannot create temporary files])
34 # Assume that if we have lstat, we can also check symlinks.
35 if test $ac_cv_func_lstat = yes; then
36 ln -s conftest.f conftest.lnk
38 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
41 ]], [if (rename ("conftest.f", "conftest.f1/") == 0) return 1;
42 if (rename ("conftest.d1", "conftest.d2/") != 0) return 2;
44 if (rename ("conftest.f", "conftest.lnk/") == 0) return 3;
47 [gl_cv_func_rename_slash_dst_works=yes],
48 [gl_cv_func_rename_slash_dst_works=no],
49 dnl When crosscompiling, assume rename is broken.
50 [gl_cv_func_rename_slash_dst_works="guessing no"])
51 rm -rf conftest.f conftest.f1 conftest.d1 conftest.d2 conftest.lnk
53 if test "x$gl_cv_func_rename_slash_dst_works" != xyes; then
56 AC_DEFINE([RENAME_TRAILING_SLASH_DEST_BUG], [1],
57 [Define if rename does not correctly handle slashes on the destination
58 argument, such as on Solaris 10 or NetBSD 1.6.])
61 dnl SunOS 4.1.1_U1 mistakenly forbids rename("dir/","name").
62 dnl Solaris 9 mistakenly allows rename("file/","name").
63 dnl FreeBSD 7.2 mistakenly allows rename("link-to-file/","name").
64 dnl These bugs require stripping trailing slash to avoid corrupting
65 dnl symlinks with a trailing slash.
66 AC_CACHE_CHECK([whether rename honors trailing slash on source],
67 [gl_cv_func_rename_slash_src_works],
68 [rm -rf conftest.f conftest.d1 conftest.d2 conftest.lnk
69 touch conftest.f && mkdir conftest.d1 ||
70 AC_MSG_ERROR([cannot create temporary files])
71 # Assume that if we have lstat, we can also check symlinks.
72 if test $ac_cv_func_lstat = yes; then
73 ln -s conftest.f conftest.lnk
75 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
78 ]], [if (rename ("conftest.f/", "conftest.d2") == 0) return 1;
79 if (rename ("conftest.d1/", "conftest.d2") != 0) return 2;
81 if (rename ("conftest.lnk/", "conftest.f") == 0) return 3;
84 [gl_cv_func_rename_slash_src_works=yes],
85 [gl_cv_func_rename_slash_src_works=no],
86 dnl When crosscompiling, assume rename is broken.
87 [gl_cv_func_rename_slash_src_works="guessing no"])
88 rm -rf conftest.f conftest.d1 conftest.d2 conftest.lnk
90 if test "x$gl_cv_func_rename_slash_src_works" != xyes; then
93 AC_DEFINE([RENAME_TRAILING_SLASH_SOURCE_BUG], [1],
94 [Define if rename does not correctly handle slashes on the source
95 argument, such as on Solaris 9 or cygwin 1.5.])
98 dnl NetBSD 1.6 and cygwin 1.5.x mistakenly reduce hard link count
99 dnl on rename("h1","h2").
100 dnl This bug requires stat'ting targets prior to attempting rename.
101 AC_CACHE_CHECK([whether rename manages hard links correctly],
102 [gl_cv_func_rename_link_works],
103 [rm -rf conftest.f conftest.f1
104 if touch conftest.f && ln conftest.f conftest.f1 &&
105 set x `ls -i conftest.f conftest.f1` && test "$2" = "$4"; then
106 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
110 ]], [if (rename ("conftest.f", "conftest.f1")) return 1;
111 if (unlink ("conftest.f1")) return 2;
112 if (rename ("conftest.f", "conftest.f")) return 3;
113 if (rename ("conftest.f1", "conftest.f1") == 0) return 4;])],
114 [gl_cv_func_rename_link_works=yes],
115 [gl_cv_func_rename_link_works=no],
116 dnl When crosscompiling, assume rename is broken.
117 [gl_cv_func_rename_link_works="guessing no"])
119 gl_cv_func_rename_link_works="guessing no"
121 rm -rf conftest.f conftest.f1
123 if test "x$gl_cv_func_rename_link_works" != xyes; then
126 AC_DEFINE([RENAME_HARD_LINK_BUG], [1],
127 [Define if rename fails to leave hard links alone, as on NetBSD 1.6
131 dnl Cygwin 1.5.x mistakenly allows rename("dir","file").
132 dnl mingw mistakenly forbids rename("dir1","dir2").
133 dnl These bugs require stripping trailing slash to avoid corrupting
134 dnl symlinks with a trailing slash.
135 AC_CACHE_CHECK([whether rename manages existing destinations correctly],
136 [gl_cv_func_rename_dest_works],
137 [rm -rf conftest.f conftest.d1 conftest.d2
138 touch conftest.f && mkdir conftest.d1 conftest.d2 ||
139 AC_MSG_ERROR([cannot create temporary files])
140 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
143 ]], [if (rename ("conftest.d1", "conftest.d2") != 0) return 1;
144 if (rename ("conftest.d2", "conftest.f") == 0) return 2;])],
145 [gl_cv_func_rename_dest_works=yes],
146 [gl_cv_func_rename_dest_works=no],
147 dnl When crosscompiling, assume rename is broken.
148 [gl_cv_func_rename_dest_works="guessing no"])
149 rm -rf conftest.f conftest.d1 conftest.d2
151 if test "x$gl_cv_func_rename_dest_works" != xyes; then
154 AC_DEFINE([RENAME_DEST_EXISTS_BUG], [1],
155 [Define if rename does not work when the destination file exists,
156 as on Cygwin 1.5 or Windows.])