I think the behavior depends on the process that populates the dirent
fields for the given path you are querying.
For example, try out the following test. The d_namelen values are
correct for "/bin" but incorrect for "/proc/boot" (like what you are
seeing).
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
int printdir(char* path)
{
DIR* dirp;
struct dirent* direntp;
printf("\ncontents of %s\n", path);
dirp = opendir( path );
if( dirp != NULL ) {
for(;;) {
direntp = readdir( dirp );
if( direntp == NULL ) break;
printf( "\"%s\", %d, %d\n", direntp->d_name,
direntp->d_namelen, strlen(direntp->d_name) );
}
closedir( dirp );
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
int main( void )
{
printdir("/proc/boot");
return printdir("/bin");
}
Running on an x86 6.4.1 installation in vmware:
contents of /proc/boot
"startup-script", 15, 14
"unlink_list", 12, 11
"procnto-smp-instr", 18, 17
"libc.so.3", 10, 9
"libc.so", 8, 7
etc.
contents of /bin
".", 1, 1
"..", 2, 2
"ap", 2, 2
"aps", 3, 3
"asa", 3, 3
"cat", 3, 3
"chgrp", 5, 5
"chmod", 5, 5
"chown", 5, 5
"confstr", 7, 7
etc.
Note, however, when I try the same test on a 6.5.0 x86 installation, the
direntp->d_namelen are ok for /proc/boot.
Regards,
asherk
-----Original Message-----
From: Markus Schmoelzer [mailto:community-noreply@qnx.com]
Sent: Friday, July 01, 2011 8:37 AM
To: general-filesystems
Subject: readdir() sets wrong dirent->d_namelen value?
Hi everybody,
as written in the QNX documentation on "struct dirent", the "d_namelen"
member holds the number of characters of the directory entry name,
stored in the "d_name" member (not regarding the terminating '\0').
I'm using QNX 6.4.1 on an embedded PPC target. My problem is, that the
string length of "d_name" is actually 1 character less than "d_namelen"
indicates (e.g. a directory entry named "bitmaps" has a "d_namelen"
value of 8 instead of 7).
Is this a flaw in QNX 6.4.1, or is there a reasonable explanation to
this? One could be, that "d_namelen" in fact regards the terminating
'\0', or it accounts for a preceeding '/' character (which is however
not stored in the "d_name" member of the dirent struct)...
I would appreciate any comments on this matter.
Many thanks in advance!
_______________________________________________
General
http://community.qnx.com/sf/go/post87017