[Issue 4955] New: struct dirent.d_type is not a mask

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 29 04:18:18 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4955

           Summary: struct dirent.d_type is not a mask
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: tomash.brechko at gmail.com


--- Comment #0 from Tomash Brechko <tomash.brechko at gmail.com> 2010-09-29 04:18:02 PDT ---
In phobos/std/file.d:

version(Posix) struct DirEntry
{
    ...
    bool isdir() const
    {
        return (d_type & DT_DIR) != 0;
    }

    bool isfile() const
    {
        return (d_type & DT_REG) != 0;
    }

But struct dirent.d_type is not a mask (unlike struct stat.st_mode), it's a
plain value, and should be compared (d_type == DT_DIR) and (d_type == DT_REG)
respectively.  To test, compile the following:

// dir.d
import std.file;
import std.stdio;

void
main(string[] args)
{
  foreach (string name; dirEntries(args[1], SpanMode.depth))
    writeln(name);
}

and then do:

$ mkdir /tmp/test
$ mksock /tmp/test/sock
$ ./dir /tmp/test
std.file.FileException at std/file.d(1066): /tmp/test/sock: Not a directory
----------------
./dir() [0x804d71f]
./dir() [0x804daf8]
./dir() [0x804d95f]
./dir() [0x8049750]
./dir() [0x804d9ea]
./dir() [0x8049683]
./dir() [0x80494ef]
./dir() [0x804bf06]
./dir() [0x804be60]
./dir() [0x804bf4a]
./dir() [0x804be60]
./dir() [0x804be06]
/lib/libc.so.6(__libc_start_main+0xe6) [0x3edbb6]
./dir() [0x8049401]

See it tries to descend into /tmp/test/sock.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list