Bug in current versions of /usr/include/dirent.h ?

Frank Leonhardt freebsd-doc at fjl.co.uk
Tue Apr 20 18:21:48 UTC 2021


Weird one this! I'm currently using 12.2, but this appears to be a 
problem in recent versions.

In FreeBSD 8, dirent.h contains the following:

/* structure describing an open directory. */
typedef struct _dirdesc {
         int     dd_fd;          /* file descriptor associated with 
directory */
         long    dd_loc;         /* offset in current buffer */
         long    dd_size;        /* amount of data returned by 
getdirentries */
         char    *dd_buf;        /* data buffer */
         int     dd_len;         /* size of data buffer */
         long    dd_seek;        /* magic cookie returned by 
getdirentries */
         long    dd_rewind;      /* magic cookie for rewinding */
         int     dd_flags;       /* flags for readdir */
         struct pthread_mutex    *dd_lock;       /* lock */
         struct _telldir *dd_td; /* telldir position recording */
} DIR;

Nothing wrong there. It's the structure used by opendir() etc in the 
standard C library.

In 12.2 we've not got a structure definition, but instead a forward 
reference at line 87. DIR is typedefed on the following line. However, 
nowhere can I find where this forward reference is later resolved - 
meaning it isn't.

Has anyone got the faintest idea what's going on? I've had a look 
through the source code to see where a DIR structure is used, and it may 
as well be a (void *) - it's used as a handle returned by opendir() in 
subsequent operations but never dereferenced.

And before anyone questions why de-referencing it is necessary - first 
off, it's always been a published structure so  it's fair game. 
Secondly, full access to the dd_fd field was handy. If access to this 
structure is "deprecated" after 40 years, at the very least the handle 
should have been typedefed into something safer than a forward reference.

So what's the sane explanation?

Thanks, Frank.




More information about the freebsd-questions mailing list