2 dnl Run a program to determine whether whether link(2) follows symlinks.
3 dnl Set LINK_FOLLOWS_SYMLINKS accordingly.
5 # Copyright (C) 1999, 2000, 2001, 2004, 2005 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.
10 AC_DEFUN([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK],
13 [whether link(2) dereferences a symlink specified with a trailing slash],
14 jm_ac_cv_func_link_follows_symlink,
16 # Create a regular file.
20 # include <sys/types.h>
21 # include <sys/stat.h>
24 # define SAME_INODE(Stat_buf_1, Stat_buf_2) \
25 ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
26 && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
31 const char *file = "conftest.file";
32 const char *sym = "conftest.sym";
33 const char *hard = "conftest.hard";
34 struct stat sb_file, sb_hard;
36 /* Create a symlink to the regular file. */
37 if (symlink (file, sym))
40 /* Create a hard link to that symlink. */
44 if (lstat (hard, &sb_hard))
46 if (lstat (file, &sb_file))
49 /* If the dev/inode of hard and file are the same, then
50 the link call followed the symlink. */
51 return SAME_INODE (sb_hard, sb_file) ? 0 : 1;
54 jm_ac_cv_func_link_follows_symlink=yes,
55 jm_ac_cv_func_link_follows_symlink=no,
56 jm_ac_cv_func_link_follows_symlink=yes dnl We're cross compiling.
59 if test $jm_ac_cv_func_link_follows_symlink = yes; then
60 AC_DEFINE(LINK_FOLLOWS_SYMLINKS, 1,
61 [Define if `link(2)' dereferences symbolic links.])