Change jm_ to gl_ in AC_DEFINE'd names. Update all uses.
[gnulib.git] / m4 / link-follow.m4
1 #serial 4
2 dnl Run a program to determine whether whether link(2) follows symlinks.
3 dnl Set LINK_FOLLOWS_SYMLINKS accordingly.
4
5 AC_DEFUN([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK],
6 [dnl
7   AC_CACHE_CHECK(
8     [whether link(2) dereferences a symlink specified with a trailing slash],
9                  jm_ac_cv_func_link_follows_symlink,
10   [
11     dnl poor-man's AC_REQUIRE: FIXME: repair this once autoconf-3 provides
12     dnl the appropriate framework.
13     test -z "$ac_cv_header_unistd_h" \
14       && AC_CHECK_HEADERS(unistd.h)
15
16     # Create a regular file.
17     echo > conftest.file
18     AC_TRY_RUN(
19       [
20 #       include <sys/types.h>
21 #       include <sys/stat.h>
22 #       ifdef HAVE_UNISTD_H
23 #        include <unistd.h>
24 #       endif
25
26 #       define SAME_INODE(Stat_buf_1, Stat_buf_2) \
27           ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
28            && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
29
30         int
31         main ()
32         {
33           const char *file = "conftest.file";
34           const char *sym = "conftest.sym";
35           const char *hard = "conftest.hard";
36           struct stat sb_file, sb_hard;
37
38           /* Create a symlink to the regular file. */
39           if (symlink (file, sym))
40             abort ();
41
42           /* Create a hard link to that symlink.  */
43           if (link (sym, hard))
44             abort ();
45
46           if (lstat (hard, &sb_hard))
47             abort ();
48           if (lstat (file, &sb_file))
49             abort ();
50
51           /* If the dev/inode of hard and file are the same, then
52              the link call followed the symlink.  */
53           return SAME_INODE (sb_hard, sb_file) ? 0 : 1;
54         }
55       ],
56       jm_ac_cv_func_link_follows_symlink=yes,
57       jm_ac_cv_func_link_follows_symlink=no,
58       jm_ac_cv_func_link_follows_symlink=yes dnl We're cross compiling.
59     )
60   ])
61   if test $jm_ac_cv_func_link_follows_symlink = yes; then
62     AC_DEFINE(LINK_FOLLOWS_SYMLINKS, 1,
63       [Define if `link(2)' dereferences symbolic links.])
64   fi
65 ])