---------------------------------------- #include <errno.h> #include <string.h> #include <stdio.h> #include <sys/types.h> #include <dirent.h>
struct {
struct dirent entry;
char buffer[4096];
} entry;int main (void)
{
DIR* dir;
struct dirent* result;
dir = opendir(".");
if (dir == NULL)
{
fprintf(stderr, "Can't open .: %s", strerror(errno));
exit(1);
} for (;;)
{
#ifdef _POSIX_PTHREAD_SEMANTICS
int err = readdir_r(dir, &entry.entry, &result);
if (result != &entry.entry)
{
fprintf(stderr, "Can't read .: %s\n", strerror(err));
exit(err != 0);
}
#else
result = readdir_r(dir, &entry.entry);
if (result != &entry.entry)
{
fprintf(stderr, "Can't read .: %s\n", strerror(errno));
exit(errno != 0);
}
#endif printf("./%s\n", entry.entry.d_name);
}
closedir(dir);
return 0;
}
----------------------------------------
When compiled with
cc -D_REENTRANT -o dir dir.c -lpthread
the progam lists the directory, prints
Can't read .: Error 0
and exits with 0. However, when -D_POSIX_PTHREAD_SEMANTICS is added to the command line, it lists the contents of the directory, but then prints
Can't read .: Invalid argument
and exits with 1.
I /think/ this is a bug in Solaris' readdir_r, which, by all accounts, should set "result" to NULL and return 0 when it reaches the end of the directory. This implementation does set "result" to NULL, but returns EINVAL instead.
I'm not sure what to do here. Clearly, not defining _POSIX_PTHREAD_SEMANTICS is not an option, and using readdir instead would probably not be reentrant. We could #ifdef the termination condition in apr_dir_read(), but that seems like a dirty hack to me.
Unfortunately, the Solaris 2.6 machine I have access to is going away this week, and when it comes bach, it'll be Solaris 8. So I'll have to stop working on this, and am hereby dropping it into somebody else's lap.
Brane
-- Brane Čibej home: <[EMAIL PROTECTED]> http://www.xbc.nu/brane/ work: <[EMAIL PROTECTED]> http://www.hermes-softlab.com/ ACM : <[EMAIL PROTECTED]> http://www.acm.org/
