d_type contains stats on the current file/directory.
It exists in DJGPP, and all the various UNIX based OSs I've worked with.
Combining with stat is very slow when working with large directories.
Since readdir() wraps to native Win32 functions which do contain d_type
like data, why can't it be implemented?
From: Andy Ross <andy@pl...> - 2003-04-23 19:49:32
> It exists in DJGPP, and all the various UNIX based OSs I've worked
I might be wrong on this, but IIRC Solaris does not support the field
at all. It's a BSDism. And on Linux, whose headers claim to support
it (but, tellingly, whose man pages don't mention it), the d_type
field is a silent *lie* for a directory read over NFS. It always
Like I said earlier: the problem is fundamental. Not all filesystems
are capable of storing type information in the directory (until today,
I thought ext3 was one of them). Using an API that claims otherwise
is going to get you into trouble.
> Combining with stat is very slow when working with large
You haven't tested that, because it's only vaguely true. Doing an
iterated readdir() over a directory with 13k files takes 137ms on my
(rather slow -- 166MHz) linux gateway. Doing a stat() on each file
along the way takes about 300. And those numbers are worst-case, for
data in the cache. Doing it on a cold disk is dominated by seek time,
much slower, and essentially identical between the cases.
If you do the math, you're basically paying only the extra thousand or
so cycles for the extra system call. It's slower, but I wouldn't call
that "very" slow by any means.
> Since readdir() wraps to native Win32 functions which do contain
> d_type like data, why can't it be implemented?
Bottom line: the d_type field is a non-portable hack. It works only
on some systems some of the time. If you want to write non-portable
code, you would be best served by writing to the native API of the
system, not by trying to shoe-horn an obscure and best forgotten
unixism onto Win32.
Andrew J. Ross Beyond the Ordinary Plausibility Productions
Sole Proprietor Beneath the Infinite Hillsboro, OR
Experience... the Plausible?