view m4/link-follow.m4 @ 6275:fd0ccce602e4

Sync from coreutils. * .cppi-disable: Add regcomp.c, regex_internal.c, regex_internal.h, stat-time.h. * argmatch.h: Include verify.h (ARGMATCH_VERIFY): Use verify rather than rolling our own. (ARGMATCH_ASSERT): Remove; unused. * canonicalize.c: Assume STDC_HEADERS. * exclude.c: Include "strcase.h". * regex_internal.h [!defined _LIBC]: Likewise. * getusershell.c: Include stdio--.h rather than stdio.h and stdio-safer.h. (getusershell): Call fopen, not fopen_safer. * save-cwd.c: Include fcntl--.h rather than fcntl.h. Do not include unistd-safer.h. (save_cwd): Don't call fd_safer; no longer needed now that we include fcntl--.h. * modules/argmatch (Depends-on): Add verify. * modules/getloadavg (Depends-on): Depend on fcntl-safer, not unistd-safer. * modules/save-cwd (Depends-on): Likewise. * backupfile.m4, calloc.m4, chown.m4, cloexec.m4, dup2.m4: * fileblocks.m4, free.m4, ftruncate.m4, getcwd.m4, getpagesize.m4: * getugroups.m4, group-member.m4, idcache.m4, link-follow.m4: * mkstemp.m4, mktime.m4, mountlist.m4, nanosleep.m4, pathmax.m4: * physmem.m4, posixver.m4, putenv.m4, safe-read.m4, same.m4: * save-cwd.m4, stdio-safer.m4, unistd-safer.m4, unlinkdir.m4: * userspec.m4, xgetcwd.m4, xreadlink.m4: Don't bother checking for string.h, stdlib.h, unistd.h. * fts.m4 (gl_FUNC_FTS_CORE): Don't require AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK; that's now the lstat module's job. * jm-macros.m4 (gl_MACROS): Likewise. * prereq.m4 (gl_PREREQ): Add gl_FUNC_LSTAT. * backupfile.c: Use ARGMATCH_VERIFY, just in case. * posixtm.c (posixtime) [lint]: Initialize *all* of tm0, not just the .tm_year member, since otherwise gcc-4.0 would now warn about tm_zone, tm_gmtoff, tm_isdst, tm_yday, tm_wday. * quotearg.c (quotearg_n_options): Change code to be suboptimal, in order to avoid an unsuppressible warning from gcc on 64-bit systems. * lstat.m4 (gl_FUNC_LSTAT): Use AC_LIBSOURCES to require lstat.c and lstat.h. Remove obsolete comment. * xreadlink.m4: Use AC_LIBSOURCES and AC_LIBOBJ. * xstrtod.m4: Likewise.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 23 Sep 2005 04:15:13 +0000
parents 87c42e194f4a
children c34c3fd8f414
line wrap: on
line source

#serial 7
dnl Run a program to determine whether whether link(2) follows symlinks.
dnl Set LINK_FOLLOWS_SYMLINKS accordingly.

# Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_AC_FUNC_LINK_FOLLOWS_SYMLINK],
[dnl
  AC_CACHE_CHECK(
    [whether link(2) dereferences a symlink specified with a trailing slash],
		 jm_ac_cv_func_link_follows_symlink,
  [
    # Create a regular file.
    echo > conftest.file
    AC_TRY_RUN(
      [
#       include <sys/types.h>
#       include <sys/stat.h>
#       include <unistd.h>

#       define SAME_INODE(Stat_buf_1, Stat_buf_2) \
	  ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
	   && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)

	int
	main ()
	{
	  const char *file = "conftest.file";
	  const char *sym = "conftest.sym";
	  const char *hard = "conftest.hard";
	  struct stat sb_file, sb_hard;

	  /* Create a symlink to the regular file. */
	  if (symlink (file, sym))
	    abort ();

	  /* Create a hard link to that symlink.  */
	  if (link (sym, hard))
	    abort ();

	  if (lstat (hard, &sb_hard))
	    abort ();
	  if (lstat (file, &sb_file))
	    abort ();

	  /* If the dev/inode of hard and file are the same, then
	     the link call followed the symlink.  */
	  return SAME_INODE (sb_hard, sb_file) ? 0 : 1;
	}
      ],
      jm_ac_cv_func_link_follows_symlink=yes,
      jm_ac_cv_func_link_follows_symlink=no,
      jm_ac_cv_func_link_follows_symlink=yes dnl We're cross compiling.
    )
  ])
  if test $jm_ac_cv_func_link_follows_symlink = yes; then
    AC_DEFINE(LINK_FOLLOWS_SYMLINKS, 1,
      [Define if `link(2)' dereferences symbolic links.])
  fi
])