Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Apr 2021 19:21:45 +0100
From:      Frank Leonhardt <freebsd-doc@fjl.co.uk>
To:        freebsd-questions@freebsd.org
Subject:   Bug in current versions of /usr/include/dirent.h ?
Message-ID:  <fa2c4f47-f8e6-7553-6fff-2454f3cac2d8@fjl.co.uk>

next in thread | raw e-mail | index | archive | help
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.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?fa2c4f47-f8e6-7553-6fff-2454f3cac2d8>