![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to print struct in GDB | useless79 | High Level Programming | 4 | 09-06-2007 05:02 AM |
| struct tm problem | bankpro | High Level Programming | 4 | 01-20-2006 03:51 AM |
| dirent.h problem .. | qqq | High Level Programming | 3 | 03-02-2005 11:05 AM |
| save a struct | kall_ANSI | High Level Programming | 2 | 10-29-2004 08:42 AM |
| Struct Initialization | amatsaka | High Level Programming | 4 | 12-20-2002 07:25 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
struct dirent variances
Hello,
Recently I need to create a filesystem related code. I noticed lot of inconsistent documentation regarding struct dirent: 1. 'd_namlen' field info libc in chapter ''File System Interface" specifies 'd_namlen' field as length of 'd_name' string. When compiling under Linux (and GNU libc obviously) 'd_namlen' is missing. 2. 'd_reclen' this field is documented as "length of d_name" in readdir(2) whereas in '/usr/include/dirent.h' it is described as 'size of entire directory entry'. In 'info libc' 'd_reclen' is mentioned but not really described at all. 3. 'd_off' field in readdir(2) this is offset to current dirent [from start of the directory], but again in '/usr/include/dirent.h' this is "offset of next directory entry". I understand that only 'd_name' is really portable and it is enough for my purposes. But could anybody explain above? In my opinion some of inconsistencies from 2. and 3. are due to readir(2) possibly deals with kernel 'struct dirent' which can be independent of libc one. Regards, Miroslaw Regards. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Hi,
I'm assuming you have looked at the references in the readdir manpage? Code:
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* offset to the next dirent */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file */
char d_name[256]; /* filename */
};
According to POSIX, the dirent structure contains a field char d_name[] of unspecified size, with at most NAME_MAX characters preceding the terminating null byte.
POSIX.1-2001 also documents the field ino_t d_ino as an XSI extension. Use of other fields will harm the portability of your programs.
|
|
#3
|
|||
|
|||
|
Yes, 'readdir' in 2nd chapter of man pages.
|
|
#4
|
||||
|
||||
|
The readdir system call man page says "This is not the function you are interested in. Look at readdir(3) for the POSIX conforming C library interface. This page documents the bare kernel system call interface, which can change, and which is superseded by getdents(2)."
|
||||
| Google The UNIX and Linux Forums |