Sponsored Content
Full Discussion: seekdir()? what does it do?
Top Forums UNIX for Dummies Questions & Answers seekdir()? what does it do? Post 302490062 by Perderabo on Sunday 23rd of January 2011 07:51:35 PM
Old 01-23-2011
Remember that a directory is a list of filenames, it is not the files themselves. The readdir, telldir, seekdir functions are for processing a directory. That said, I have never used seekdir (or telldir) for anything. I rather doubt that I ever will. I really can't construct any hypothetical situation where they might be useful.

But if you wanted to write a C program that did the equivalent of "ls /etc", you would opendir() /etc, use readdir() to read the filenames, sort those filnames, and then display them.

When you got to,say, passwd, you could do a telldir() to remember this location in the directory. Then you could use readdir say 5 more times to read the next 5 filenames. Now you could use seekdir to go back to that entry for the file called passwd. Why you would want to do that beats me.
 
seekdir(3C)						   Standard C Library Functions 					       seekdir(3C)

NAME
seekdir - set position of directory stream SYNOPSIS
#include <sys/types.h> #include <dirent.h> void seekdir(DIR *dirp, long int loc); DESCRIPTION
The seekdir() function sets the position of the next readdir(3C) operation on the directory stream specified by dirp to the position speci- fied by loc. The value of loc should have been returned from an earlier call to telldir(3C). The new position reverts to the one associated with the directory stream when telldir() was performed. If the value of loc was not obtained from an earlier call to telldir() or if a call to rewinddir(3C) occurred between the call to telldir () and the call to seekdir(), the results of subsequent calls to readdir() are unspecified. RETURN VALUES
The seekdir() function returns no value. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
opendir(3C), readdir(3C), rewinddir(3C), telldir(3C), attributes(5), standards(5) SunOS 5.11 14 Aug 2002 seekdir(3C)
All times are GMT -4. The time now is 03:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy