rename: fix Solaris 9 bug
[pspp] / m4 / rename.m4
1 # serial 16
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 SunOS 4.1.1_U1 mistakenly forbids rename("dir/","name").
22   dnl Solaris 9 mistakenly allows rename("file/","name").
23   AC_CACHE_CHECK([whether rename honors trailing slash on source],
24     [gl_cv_func_rename_slash_src_works],
25     [rm -rf conftest.f conftest.d1 conftest.d2
26     touch conftest.f && mkdir conftest.d1 ||
27       AC_MSG_ERROR([cannot create temporary files])
28     AC_RUN_IFELSE([AC_LANG_PROGRAM([[
29 #       include <stdio.h>
30 #       include <stdlib.h>
31 ]], [if (rename ("conftest.f/", "conftest.d2") == 0) return 1;
32      if (rename ("conftest.d1/", "conftest.d2") != 0) return 2;])],
33       [gl_cv_func_rename_slash_src_works=yes],
34       [gl_cv_func_rename_slash_src_works=no],
35       dnl When crosscompiling, assume rename is broken.
36       [gl_cv_func_rename_slash_src_works="guessing no"])
37     rm -rf conftest.f conftest.d1 conftest.d2
38   ])
39   if test "x$gl_cv_func_rename_slash_src_works" != xyes; then
40     AC_LIBOBJ([rename])
41     REPLACE_RENAME=1
42     AC_DEFINE([RENAME_TRAILING_SLASH_BUG], [1],
43       [Define if rename does not correctly handle slashes on the source
44        argument, such as on Solaris 9 or cygwin 1.5.])
45   fi
46
47   AC_CACHE_CHECK([whether rename is broken when the destination exists],
48     [gl_cv_func_rename_dest_exists_bug],
49     [case "$host_os" in
50       mingw*) gl_cv_func_rename_dest_exists_bug=yes ;;
51       *) gl_cv_func_rename_dest_exists_bug=no ;;
52     esac
53   ])
54   if test $gl_cv_func_rename_dest_exists_bug = yes; then
55     AC_LIBOBJ([rename])
56     REPLACE_RENAME=1
57     AC_DEFINE([RENAME_DEST_EXISTS_BUG], [1],
58       [Define if rename does not work when the destination file exists,
59        as on Windows.])
60   fi
61 ])