Saving Position Within a Directory

It is possible to use the function telldir(3) to save a position within a directory. The function synopsis is as follows:

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

long telldir(const DIR *dirp);

Given the input pointer dirp, which points to an open DIR structure returned by opendir(3), this function returns an offset into the directory for later use by seekdir(3). The offset returned is greater than or equal to zero if it is successful. A -1L value is returned if it fails, and the error code is found in errno.

Note

Some UNIX platforms may have a slightly different type definition for telldir(3). For example, SGI's IRIX 6.5 defines its telldir(3) as follows:

off_t telldir (DIR *dirp);

Note that the returned ...

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.