bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Patch] Add dirent.d_type support to Cygwin 1.7 ?


From: Jim Meyering
Subject: Re: [Patch] Add dirent.d_type support to Cygwin 1.7 ?
Date: Sat, 29 Nov 2008 16:46:02 +0100

Jim Meyering <address@hidden> wrote:
> "James Youngman" <address@hidden> wrote:
>> As far as I can see, the variable type is assigned in the function
>> above, but never used.   Did you mean to use "type" rather than
>> "dtype" in the expression which assigns to st->st_mode?
>
> Thanks again.
> Here's the patch I'll push as soon as you say ok:

I hadn't tested enough after all.
That didn't work either.  But this does.
With *it*, all 1133 of find's tests really do pass:

>From fb3d1318c0ea7f675b0702897c35f83198efdae8 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 29 Nov 2008 16:08:09 +0100
Subject: [PATCH] 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.
---
 lib/fts.c |   22 +---------------------
 1 files changed, 1 insertions(+), 21 deletions(-)

diff --git a/lib/fts.c b/lib/fts.c
index 35def60..4689e80 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1011,26 +1011,6 @@ fts_compare_ino (struct _ftsent const **a, struct 
_ftsent const **b)
          : 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 @@ set_stat_type (struct stat *st, unsigned int dtype)
     default:
       type = 0;
     }
-  st->st_mode = dtype << s_ifmt_shift_bits ();
+  st->st_mode = type;
 }

 /*
--
1.6.0.4.1101.g642f8




reply via email to

[Prev in Thread] Current Thread [Next in Thread]