FAT | RFS | XFS | ZFS
readdir_open()
PROTOTYPE
#include <posix.h>
struct dirent *readdir_open(DIR *dirp, int oflag, int *fidp);
DESCRIPTION
readdir_open() is a non-standard routine that combines the behavior of readdir() and open(). It is an optimization since the name lookup otherwise required by open() on the dirent structure’s d_name entry is omitted.
The readdir_open() dirp parameter and return value are the same as for readdir(). The oflag parameter is the same as for open() and the *fidp output is the same as open()’s return value. See the readdir() and open() pages for information on those.
EXAMPLE
/*-------------------------------------------------------------------*/
/* Read all of every file in the current directory. */
/*-------------------------------------------------------------------*/
dir = opendir(".");
if (dir == NULL)
error("opendir() failed");
sum = 0;
while (readdir_open(dir, O_RDONLY, &fid))
{
for (;;)
{
rc = read(fid, buf, BUF_SIZE);
if (rc > 0)
sum += rc;
if (rc < BUF_SIZE)
break;
}
if (close(fid))
error("close() error");
}
closedir(dir);
printf("sum=%d\n", sum);