Replace uses of obsolete autoconf macros in Jim's modules.
[gnulib.git] / m4 / link-follow.m4
1 # serial 12
2 dnl Run a program to determine whether link(2) follows symlinks.
3 dnl Set LINK_FOLLOWS_SYMLINKS accordingly.
4
5 # Copyright (C) 1999-2001, 2004-2006, 2009 Free Software Foundation, Inc.
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 AC_DEFUN([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK],
11 [dnl
12   AC_CACHE_CHECK([whether link(2) dereferences a symlink],
13                  gl_ac_cv_func_link_follows_symlink,
14   [
15     # Create a regular file.
16     echo > conftest.file
17     AC_RUN_IFELSE([AC_LANG_SOURCE([[
18 #       include <sys/types.h>
19 #       include <sys/stat.h>
20 #       include <unistd.h>
21 #       include <stdlib.h>
22
23 #       define SAME_INODE(Stat_buf_1, Stat_buf_2) \
24           ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
25            && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
26
27         int
28         main ()
29         {
30           const char *file = "conftest.file";
31           const char *sym = "conftest.sym";
32           const char *hard = "conftest.hard";
33           struct stat sb_file, sb_hard;
34
35           /* Create a symlink to the regular file. */
36           if (symlink (file, sym))
37             abort ();
38
39           /* Create a hard link to that symlink.  */
40           if (link (sym, hard))
41             abort ();
42
43           if (lstat (hard, &sb_hard))
44             abort ();
45           if (lstat (file, &sb_file))
46             abort ();
47
48           /* If the dev/inode of hard and file are the same, then
49              the link call followed the symlink.  */
50           return SAME_INODE (sb_hard, sb_file) ? 0 : 1;
51         }
52       ]])],
53       [gl_ac_cv_func_link_follows_symlink=yes],
54       [gl_ac_cv_func_link_follows_symlink=no],
55       [gl_ac_cv_func_link_follows_symlink=yes] dnl We're cross compiling.
56     )
57   ])
58   if test $gl_ac_cv_func_link_follows_symlink = yes; then
59     AC_DEFINE([LINK_FOLLOWS_SYMLINKS], [1],
60       [Define if `link(2)' dereferences symbolic links.])
61   fi
62 ])