[patch] Use thread safe readdir_r instead of readdir

John (J5) Palmieri johnp at redhat.com
Mon Sep 11 09:15:09 PDT 2006


I modified the function a bit.  Returning -1 as a size_t is wrong so I
have it return a bool and take a size_t pointer out parameter instead.

On Fri, 2006-09-08 at 21:31 -0400, Havoc Pennington wrote:
> I went googling to see if readdir_r is portable and found this:
> http://lists.grok.org.uk/pipermail/full-disclosure/2005-November/038295.html
> 
> We should probably use the buffer size function from there, appended.
> 
> I'm guessing there's some portability wonkiness that will come up too, 
> but we can just wait and see what BSD and OS X users report.
> 
> Havoc
> 
>     /* Calculate the required buffer size (in bytes) for directory
>      * entries read from the given directory handle.  Return -1 if this
>      * this cannot be done. 
> 
>      * If you use autoconf, include fpathconf and dirfd in your
>      * AC_CHECK_FUNCS list.  Otherwise use some other method to detect
>      * and use them where available.
>      */
> 
>      size_t dirent_buf_size(DIR * dirp)
>      {
>          long name_max;
>      #   if defined(HAVE_FPATHCONF) && defined(HAVE_DIRFD) \
>             && defined(_PC_NAME_MAX)
>              name_max = fpathconf(dirfd(dirp), _PC_NAME_MAX);
>              if (name_max == -1)
>      #           if defined(NAME_MAX)
>                      name_max = NAME_MAX;
>      #           else
>                      return (size_t)(-1);
>      #           endif
>      #   else
>      #       if defined(NAME_MAX)
>                  name_max = NAME_MAX;
>      #       else
>      #           error "buffer size for readdir_r cannot be determined"
>      #       endif
>      #   endif
>          return (size_t)offsetof(struct dirent, d_name) + name_max + 1;
>      }
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-use-thread-safe-readdir-2.patch
Type: text/x-patch
Size: 4384 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20060911/631a96b3/dbus-use-thread-safe-readdir-2.bin


More information about the dbus mailing list