[Issue 283] incorrect std.c.linux.linux.dirent definition / listdir does not decend into subdirs on linux

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Sun Apr 29 15:05:52 PDT 2007


Frits van Bommel kirjoitti:
> d-bugmail at puremagic.com wrote:
>> ------- Comment #1 from thomas-dloop at kuehne.cn  2007-04-29 02:09 -------
>> std.c.linux.linux.dirent is defined as
>>
>> #   struct dirent
>> #    {
>> #       int d_ino;
>> #       off_t d_off;
>> #       ushort d_reclen;
>> #       ubyte d_type;
>> #       char[256] d_name;
>> #    }
>>
>> It is just luck that the current std.file.listdir functions don't
>> segfault on Linux
>> because the above structure should be named dirent64 not dirent.
>>
>> /usr/include/linux/dirent.h :
>>
>> # #ifndef _LINUX_DIRENT_H
>> # #define _LINUX_DIRENT_H
>> #
>> # #include <linux/types.h>
>> #
>> # struct dirent {
>> #    long      d_ino;
>> #    __kernel_off_t   d_off;
>> #    unsigned short   d_reclen;
>> #    char      d_name[256]; /* We must not include limits.h! */
>> # };
>> #
>> # struct dirent64 {
>> #    __u64      d_ino;
>> #    __s64      d_off;
>> #    unsigned short   d_reclen;
>> #    unsigned char   d_type;
>> #    char      d_name[256];
>> # };
>> #
>> #
>> # #endif
>>
>> Either rename the structure to dirent64 and use readdir64 in
>> std.file.listdir or fix the definition
>> and rewrite std.file.DirEntry.init/isdir/isfile
> 
> Actually, it looks like the current structure is a weird mix of dirent
> and dirent64. It has dirent64's d_type element, but the types of d_ino
> and d_off are both 32-bit signed integers (like in dirent) instead of
> unsigned 64-bit an signed 64-bit, respectively (like in dirent64).
> 
> So it should either be:
> ---
> struct dirent {
>     int d_ino;
>     off_t d_off;
>     ushort d_reclen;
>     char[256] d_name;
> }
> ---
> or:
> ---
> struct dirent64 {
>     ulong d_ino;
>     long d_off;
>     ushort d_reclen;
>     ubyte d_type;
>     char[256] d_name;
> }

That's interesting. Tango had the same problem (although IIRC dirent
struct in Tango looked exactly the same as on my system .h files). It
still didn't work. Tango team switched it to use stat, which I think is
what it uses even now. At least that works.


More information about the Digitalmars-d-bugs mailing list