struct dirent question

Peter Jeremy peterjeremy at optushome.com.au
Thu Aug 17 08:40:47 UTC 2006


On Wed, 2006-Aug-16 15:54:25 -0700, Micah wrote:
>I think you could fake it as follows:
>
>struct dirent {
>        __uint32_t d_fileno;            /* file number of entry */
>        __uint16_t d_reclen;            /* length of this record */
>        __uint8_t  d_type;              /* file type, see below */
>        __uint8_t  d_namlen;            /* length of string in d_name */
>#define MAXNAMLEN 255
>        char    d_name[MAXNAMLEN + 1];  /* name must be no longer than 
>this */
>#if !__BSD_VISIBLE
>#undef MAXNAMLEN
>#endif
>};

Macro definitions don't nest so this isn't safe.  Consider some code that
does:

#define	MAXNAMLEN	1024
...
#include <sys/dirent.h>
...
char	mybuffer[MAXNAMLEN];

-- 
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20060817/d88fd983/attachment.pgp


More information about the freebsd-hackers mailing list