www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4955] New: struct dirent.d_type is not a mask

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: tomash.brechko gmail.com


--- Comment #0 from Tomash Brechko <tomash.brechko 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 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: -------
Sep 29 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4955


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com


--- Comment #1 from Andrei Alexandrescu <andrei metalanguage.com> 2010-09-29
09:38:20 PDT ---
Thanks for the catch!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 29 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4955



--- Comment #2 from Andrei Alexandrescu <andrei erdani.com> 2013-02-26 08:58:04
PST ---
The code has been changed since, and my OSX tests suggests this has been fixed.
OK to close?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4955


Tomash Brechko <tomash.brechko gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from Tomash Brechko <tomash.brechko gmail.com> 2013-02-26
09:42:32 PST ---
Closing, the bug has been fixed a long time ago.

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