# HG changeset patch # User Jim Meyering # Date 1227971289 -3600 # Node ID 70fc7855343ac23e8743d6d9b4ce1febe443ef7b # Parent 36479bd141eeffef3432431601f3895f9503ac52 fts: fix a thinko * lib/fts.c (s_ifmt_shift_bits): Remove function. Not needed after all. (set_stat_type): Return S_IF*-valued "type" directly. Prompted by James Youngman's spotting a related bug. Confirmed by further testing through find. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-11-29 Jim Meyering + fts: fix a thinko + * lib/fts.c (s_ifmt_shift_bits): Remove function. Not needed after all. + (set_stat_type): Return S_IF*-valued "type" directly. + Prompted by James Youngman's spotting a related bug. + Confirmed by further testing through find. + fts: provide dirent.d_type via FTSENT.fts_statp, when possible * lib/fts.c (D_TYPE): Define. (DT_UNKNOWN, DT_BLK, DT_CHR) [HAVE_STRUCT_DIRENT_D_TYPE]: Define. diff --git a/lib/fts.c b/lib/fts.c --- a/lib/fts.c +++ b/lib/fts.c @@ -1011,26 +1011,6 @@ : b[0]->fts_statp->st_ino < a[0]->fts_statp->st_ino ? 1 : 0); } -/* Return the number of bits by which a d_type value must be shifted - left in order to put it into the S_IFMT bits of stat.st_mode. */ -static int -s_ifmt_shift_bits (void) -{ - unsigned int v = S_IFMT; /* usually, 0170000 */ - static const int MultiplyDeBruijnBitPosition[32] = - { - 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, - 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 - }; - - /* Find the smallest power of two, P (e.g., 0010000) such that P & V == P. */ - unsigned int p = v ^ (v & (v - 1)); - - /* Compute and return r = log2 (p), using code from - http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn */ - return MultiplyDeBruijnBitPosition[(uint32_t) (p * 0x077CB531UL) >> 27]; -} - /* Map the dirent.d_type value, DTYPE, to the corresponding stat.st_mode S_IF* bit and set ST.st_mode, thus clearing all other bits in that field. */ static void @@ -1063,7 +1043,7 @@ default: type = 0; } - st->st_mode = dtype << s_ifmt_shift_bits (); + st->st_mode = type; } /*