The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-17-2008
Registered User
 

Join Date: Feb 2005
Posts: 53
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.
Reply With Quote
Forum Sponsor
  #2  
Old 03-17-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 250
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.
Reply With Quote
  #3  
Old 03-17-2008
Registered User
 

Join Date: Feb 2005
Posts: 53
Yes, 'readdir' in 2nd chapter of man pages.
Reply With Quote
  #4  
Old 03-17-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,658
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)."
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0