Restoring Position Within a Directory

In order to position the directory randomly according to information saved from a prior call to telldir(3), the function seekdir(3) must be used to restore the directory position. The function synopsis is as follows:

#include <sys/types.h>
#include <dirent.h>

void seekdir(DIR *dirp, long loc);

The seekdir(3) function simply accepts the pointer to an open DIR structure and an offset loc to restore as a directory position. No success or error indication is returned for this call.

The following example shows how telldir(3) and seekdir(3) can be used together:

 DIR *dirp; /* Open DIR pointer */ long dirpos; /* Directory offset */ dirpos = telldir(dirp); /* Get offset in directory */ … seekdir(dirpos); /* Restore ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.