3 # Copyright (C) 2001, 2003, 2005-2006, 2009-2017 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, AIX 7.1 mistakenly allow 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.f2 conftest.d1 conftest.d2 conftest.lnk
32 touch conftest.f && touch conftest.f1 && 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
44 if (rename ("conftest.f1", "conftest.f2/") == 0)
46 if (rename ("conftest.d1", "conftest.d2/") != 0)
49 if (rename ("conftest.f", "conftest.lnk/") == 0)
54 [gl_cv_func_rename_slash_dst_works=yes],
55 [gl_cv_func_rename_slash_dst_works=no],
56 dnl When crosscompiling, assume rename is broken.
58 # Guess yes on glibc systems.
59 *-gnu*) gl_cv_func_rename_slash_dst_works="guessing yes" ;;
60 # Guess no on native Windows.
61 mingw*) gl_cv_func_rename_slash_dst_works="guessing no" ;;
62 # If we don't know, assume the worst.
63 *) gl_cv_func_rename_slash_dst_works="guessing no" ;;
66 rm -rf conftest.f conftest.f1 conftest.f2 conftest.d1 conftest.d2 conftest.lnk
68 case "$gl_cv_func_rename_slash_dst_works" in
72 AC_DEFINE([RENAME_TRAILING_SLASH_DEST_BUG], [1],
73 [Define if rename does not correctly handle slashes on the destination
74 argument, such as on Solaris 10 or NetBSD 1.6.])
78 dnl SunOS 4.1.1_U1 mistakenly forbids rename("dir/","name").
79 dnl Solaris 9 mistakenly allows rename("file/","name").
80 dnl FreeBSD 7.2 mistakenly allows rename("link-to-file/","name").
81 dnl These bugs require stripping trailing slash to avoid corrupting
82 dnl symlinks with a trailing slash.
83 AC_CACHE_CHECK([whether rename honors trailing slash on source],
84 [gl_cv_func_rename_slash_src_works],
85 [rm -rf conftest.f conftest.f1 conftest.d1 conftest.d2 conftest.d3 conftest.lnk
86 touch conftest.f && touch conftest.f1 && mkdir conftest.d1 ||
87 AC_MSG_ERROR([cannot create temporary files])
88 # Assume that if we have lstat, we can also check symlinks.
89 if test $ac_cv_func_lstat = yes; then
90 ln -s conftest.f conftest.lnk
98 if (rename ("conftest.f1/", "conftest.d3") == 0)
100 if (rename ("conftest.d1/", "conftest.d2") != 0)
103 if (rename ("conftest.lnk/", "conftest.f") == 0)
108 [gl_cv_func_rename_slash_src_works=yes],
109 [gl_cv_func_rename_slash_src_works=no],
110 dnl When crosscompiling, assume rename is broken.
112 # Guess yes on glibc systems.
113 *-gnu*) gl_cv_func_rename_slash_src_works="guessing yes" ;;
114 # Guess yes on native Windows.
115 mingw*) gl_cv_func_rename_slash_src_works="guessing yes" ;;
116 # If we don't know, assume the worst.
117 *) gl_cv_func_rename_slash_src_works="guessing no" ;;
120 rm -rf conftest.f conftest.f1 conftest.d1 conftest.d2 conftest.d3 conftest.lnk
122 case "$gl_cv_func_rename_slash_src_works" in
126 AC_DEFINE([RENAME_TRAILING_SLASH_SOURCE_BUG], [1],
127 [Define if rename does not correctly handle slashes on the source
128 argument, such as on Solaris 9 or cygwin 1.5.])
132 dnl NetBSD 1.6 and cygwin 1.5.x mistakenly reduce hard link count
133 dnl on rename("h1","h2").
134 dnl This bug requires stat'ting targets prior to attempting rename.
135 AC_CHECK_FUNCS_ONCE([link])
136 AC_CACHE_CHECK([whether rename manages hard links correctly],
137 [gl_cv_func_rename_link_works],
138 [if test $ac_cv_func_link = yes; then
139 rm -rf conftest.f conftest.f1 conftest.f2
140 if touch conftest.f conftest.f2 && ln conftest.f conftest.f1 &&
141 set x `ls -i conftest.f conftest.f1` && test "$2" = "$4"; then
150 if (rename ("conftest.f", "conftest.f1"))
152 if (unlink ("conftest.f1"))
155 /* Allow either the POSIX-required behavior, where the
156 previous rename kept conftest.f, or the (better) NetBSD
157 behavior, where it removed conftest.f. */
158 if (rename ("conftest.f", "conftest.f") != 0
162 if (rename ("conftest.f1", "conftest.f1") == 0)
164 if (rename ("conftest.f2", "conftest.f2") != 0)
168 [gl_cv_func_rename_link_works=yes],
169 [gl_cv_func_rename_link_works=no],
170 dnl When crosscompiling, assume rename is broken.
172 # Guess yes on glibc systems.
173 *-gnu*) gl_cv_func_rename_link_works="guessing yes" ;;
174 # Guess yes on native Windows.
175 mingw*) gl_cv_func_rename_link_works="guessing yes" ;;
176 # If we don't know, assume the worst.
177 *) gl_cv_func_rename_link_works="guessing no" ;;
181 gl_cv_func_rename_link_works="guessing no"
183 rm -rf conftest.f conftest.f1 conftest.f2
185 gl_cv_func_rename_link_works=yes
188 case "$gl_cv_func_rename_link_works" in
192 AC_DEFINE([RENAME_HARD_LINK_BUG], [1],
193 [Define if rename fails to leave hard links alone, as on NetBSD 1.6
198 dnl Cygwin 1.5.x mistakenly allows rename("dir","file").
199 dnl mingw mistakenly forbids rename("dir1","dir2").
200 dnl These bugs require stripping trailing slash to avoid corrupting
201 dnl symlinks with a trailing slash.
202 AC_CACHE_CHECK([whether rename manages existing destinations correctly],
203 [gl_cv_func_rename_dest_works],
204 [rm -rf conftest.f conftest.d1 conftest.d2
205 touch conftest.f && mkdir conftest.d1 conftest.d2 ||
206 AC_MSG_ERROR([cannot create temporary files])
213 if (rename ("conftest.d1", "conftest.d2") != 0)
215 if (rename ("conftest.d2", "conftest.f") == 0)
219 [gl_cv_func_rename_dest_works=yes],
220 [gl_cv_func_rename_dest_works=no],
221 dnl When crosscompiling, assume rename is broken.
223 # Guess yes on glibc systems.
224 *-gnu*) gl_cv_func_rename_dest_works="guessing yes" ;;
225 # Guess no on native Windows.
226 mingw*) gl_cv_func_rename_dest_works="guessing no" ;;
227 # If we don't know, assume the worst.
228 *) gl_cv_func_rename_dest_works="guessing no" ;;
231 rm -rf conftest.f conftest.d1 conftest.d2
233 case "$gl_cv_func_rename_dest_works" in
237 AC_DEFINE([RENAME_DEST_EXISTS_BUG], [1],
238 [Define if rename does not work when the destination file exists,
239 as on Cygwin 1.5 or Windows.])