Hi Kevin,

kevin wrote:
> In /usr/include/sys/dirent.h I see this:
>
> /*
>  * File-system independent directory entry.
>  */
> typedef struct dirent {
>       ino_t                  d_ino;           /* "inode number" of entry */
>       off_t                          d_off;           /* offset of disk 
> directory entry */
>       unsigned short       d_reclen;          /* length of this record */
>       char                           d_name[1];       /* name of file */
> } dirent_t;
>
> Why the *name of file* d_name[1] have only one char?
>   
The d_name field is a placeholder.  The name of the file starts at 
d_name[0], and extends
contiguously from that location.  The d_reclen field gives you the total 
size
of the dirent structure, plus the size of the string making up the 
name.  So, when
the dirent is allocated, enough space is allocated for the structure 
plus the name.
This way, there is no implicit limit on the size of the name, and the 
dirent takes
up only as much space as is actually needed for the entry.  The same thing
is done elsewhere on the system.

max

> --
> This message posted from opensolaris.org
> _______________________________________________
> opensolaris-code mailing list
> [email protected]
> http://mail.opensolaris.org/mailman/listinfo/opensolaris-code
>
>   

_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to