readdir not setting d_type 0.9.28

Rich Felker dalias at aerifal.cx
Thu Sep 7 20:59:58 UTC 2006


On Thu, Sep 07, 2006 at 01:29:18PM +0800, Rogelio Serrano wrote:
> On 9/7/06, Rich Felker <dalias at aerifal.cx> wrote:
> > On Thu, Sep 07, 2006 at 01:40:27AM +0800, Rogelio Serrano wrote:
> > > readdir is not setting d_type in struct dirent?
> > >
> > > am i missing something?
> > >
> > > hre is the test im using:
> > >
> > > #include <dirent.h>
> > > #include <stdio.h>
> > >
> > > int
> > > main()
> > > {
> > >     struct dirent * de;
> > >     DIR * mydir;
> > >
> > >     mydir = opendir("testdir");
> > >     de = readdir(mydir);
> > >     while(de)
> > >     {
> > >          printf("%d\n", de->d_type);
> > >         de = readdir(myfir);
> > >     }
> > >     closedir(mydir);
> > >     return 0;
> > > }
> > >
> > > im using 0.9.28 on 2.6.17
> >
> > This is normal because you haven't enabled large file support and
> > d_type is not supported in the old legacy syscalls without lfs.
> > However there's a workaround in current svn I believe..
> >
> 
> the manual is saying that d_type is not portable so i went ahead and
> used stat instead.

This is definitely correct, but depending on your application, it may
be useful to use d_type when it is available. If this is the only
information you need to know from stat, you can easily make your
program several times faster (and avoid excessive disk thrashing) by
using d_type and avoiding the call to stat.

Rich




More information about the uClibc mailing list