Hash :
9db27e41
Author :
Date :
2005-10-02T22:38:45
Sync from coreutils.
* lib/.cppi-disable: Add getaddrinfo.h, getdelim.h, getline.h, getpass.c
mbchar.h, mbuiter.h, strcase.h, strnlen.h, strnlen1.h.
* lib/.cvsignore: Add fts.h, search.h, t-fpending.
* lib/settime.c (settime): Fix { typo in previous patch. Also, don't
bother returning ENOSYS if settimeofday or stime fails; just let
them return whatever errno they want to return.
* lib/utimens.c: Include unistd.h, for dup2.
(futimens): Fix typo: HAVE_FUTIMESAT was misspelled in an #if.
(futimens) [! HAVE_FUTIMESAT]: If !file, set errno before returning -1.
* lib/fts-cycle.c [HAVE_CONFIG_H]: Include <config.h>.
* lib/openat-die.c: Use `#ifdef HAVE_CONFIG_H', not `#if HAVE_CONFIG_H'.
* lib/openat.c (fdopendir): Do not define if HAVE_FDOPENDIR.
Remove AT_FDCWD test.
Do not consume the fd unless successful.
* lib/openat.h (fdopendir): Do not define if HAVE_FDOPENDIR.
* lib/settime.c (settime): Move the HAVE_STIME block `up' into an #elif
block, so that we don't even try to compile it if settimeofday is
available. This works around a compilation failure on OSF1 V5.1,
due to stime requiring a `long int*' while tv_sec is `int'.
* m4/openat.m4 (gl_FUNC_OPENAT): Check for fdopendir.
* m4/ullong_max.m4 (gl_ULLONG_MAX): Simplify so that it merely
defines ULONG_MAX_LT_ULLONG_MAX. Thomas M.Ott reports that
ULLONG_MAX doesn't work with 2.7.2.1.
* m4/utimes.m4 (gl_FUNC_UTIMES): Detect the version of utimes
from glibc-2.2.5 that fails for read-only files.
* m4/chdir-long.m4 (gl_FUNC_CHDIR_LONG): Compare $gl_have_path...
against `yes', rather than just testing for nonempty.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
/* Detect cycles in file tree walks.
Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
Written by Jim Meyering.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cycle-check.h"
#include "hash.h"
/* Use each of these to map a device/inode pair to an FTSENT. */
struct Active_dir
{
dev_t dev;
ino_t ino;
FTSENT *fts_ent;
};
static bool
AD_compare (void const *x, void const *y)
{
struct Active_dir const *ax = x;
struct Active_dir const *ay = y;
return ax->ino == ay->ino
&& ax->dev == ay->dev;
}
static size_t
AD_hash (void const *x, size_t table_size)
{
struct Active_dir const *ax = x;
return (uintmax_t) ax->ino % table_size;
}
/* Set up the cycle-detection machinery. */
static bool
setup_dir (FTS *fts)
{
if (fts->fts_options & (FTS_TIGHT_CYCLE_CHECK | FTS_LOGICAL))
{
enum { HT_INITIAL_SIZE = 31 };
fts->fts_cycle.ht = hash_initialize (HT_INITIAL_SIZE, NULL, AD_hash,
AD_compare, free);
if (! fts->fts_cycle.ht)
return false;
}
else
{
fts->fts_cycle.state = malloc (sizeof *fts->fts_cycle.state);
if (! fts->fts_cycle.state)
return false;
cycle_check_init (fts->fts_cycle.state);
}
return true;
}
/* Enter a directory during a file tree walk. */
static bool
enter_dir (FTS *fts, FTSENT *ent)
{
if (fts->fts_options & (FTS_TIGHT_CYCLE_CHECK | FTS_LOGICAL))
{
struct stat const *st = ent->fts_statp;
struct Active_dir *ad = malloc (sizeof *ad);
struct Active_dir *ad_from_table;
if (!ad)
return false;
ad->dev = st->st_dev;
ad->ino = st->st_ino;
ad->fts_ent = ent;
/* See if we've already encountered this directory.
This can happen when following symlinks as well as
with a corrupted directory hierarchy. */
ad_from_table = hash_insert (fts->fts_cycle.ht, ad);
if (ad_from_table != ad)
{
free (ad);
if (!ad_from_table)
return false;
/* There was an entry with matching dev/inode already in the table.
Record the fact that we've found a cycle. */
ent->fts_cycle = ad_from_table->fts_ent;
ent->fts_info = FTS_DC;
}
}
else
{
if (cycle_check (fts->fts_cycle.state, ent->fts_statp))
{
/* FIXME: setting fts_cycle like this isn't proper.
To do what the documentation requires, we'd have to
go around the cycle again and find the right entry.
But no callers in coreutils use the fts_cycle member. */
ent->fts_cycle = ent;
ent->fts_info = FTS_DC;
}
}
return true;
}
/* Leave a directory during a file tree walk. */
static void
leave_dir (FTS *fts, FTSENT *ent)
{
if (fts->fts_options & (FTS_TIGHT_CYCLE_CHECK | FTS_LOGICAL))
{
struct stat const *st = ent->fts_statp;
struct Active_dir obj;
void *found;
obj.dev = st->st_dev;
obj.ino = st->st_ino;
found = hash_delete (fts->fts_cycle.ht, &obj);
if (!found)
abort ();
free (found);
}
}
/* Free any memory used for cycle detection. */
static void
free_dir (FTS *sp)
{
if (sp->fts_options & (FTS_TIGHT_CYCLE_CHECK | FTS_LOGICAL))
{
if (sp->fts_cycle.ht)
hash_free (sp->fts_cycle.ht);
}
else
free (sp->fts_cycle.state);
}