bug-gnulib
[Top][All Lists]
Advanced

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

[Bug-gnulib] Re: [patch] findutils-4.1.20: use d_type in struct dirent


From: James Youngman
Subject: [Bug-gnulib] Re: [patch] findutils-4.1.20: use d_type in struct dirent
Date: Thu, 18 Mar 2004 15:04:09 +0000
User-agent: Mutt/1.3.28i

On Thu, Mar 18, 2004 at 02:16:49PM +0000, Tim Waugh wrote:
> Hi,
> 
> Here is a patch (originally by Jakub Jelinek) to use d_type in struct
> dirent, if available, to avoid unnecessary stat() calls in some
> expressions.
> 
> What do you think?

It's a useful patch, but there are two things we need to think about :-

1. This includes a patch to Gnulib's savedir.c.  Gnulib guys, what do
   you think of the Gnulib patch?

2. It's a significant piece of code, so the FSF will want a copyright
   disclaimer before I can include the code.  Is Jakub Jelinek the only 
   author of the patch, or does it include contributions from other people 
   too?

So that the Gnulib guys know what I am referring to, the
Gnulib-specific parts of the patch appear below.  (By the way, how
does D_TYPE_IN_DIRENT get #defined?)


Tim.
*/

--- findutils-4.1.20/gnulib/lib/savedir.c.d_type        2001-08-31 
10:09:53.000000000 +0100
+++ findutils-4.1.20/gnulib/lib/savedir.c       2004-03-18 13:58:58.000000000 
+0000
@@ -65,7 +65,9 @@
 
 /* Return a freshly allocated string containing the filenames
    in directory DIR, separated by '\0' characters;
-   the end is marked by two '\0' characters in a row.
+   if D_TYPE_IN_DIRENT is defined, this is followed by
+   one character with file type (DT_*);
+   the end is marked by "" filename.
    Return NULL (setting errno) if DIR cannot be opened, read, or closed.  */
 
 #ifndef NAME_SIZE_DEFAULT
@@ -97,6 +99,9 @@
       if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
        {
          size_t entry_size = strlen (entry) + 1;
+#ifdef D_TYPE_IN_DIRECT
+         entry_size++;
+#endif
          if (used + entry_size < used)
            xalloc_die ();
          if (allocated <= used + entry_size)
@@ -111,7 +116,10 @@
 
              name_space = xrealloc (name_space, allocated);
            }
-         memcpy (name_space + used, entry, entry_size);
+         memcpy (name_space + used, entry, entry_size - 1);
+#ifdef D_TYPE_IN_DIRENT
+         name_space[used + entry_size - 1] = dp->d_type;
+#endif
          used += entry_size;
        }
     }




reply via email to

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