SEEKDIR(3P)
π SEEKDIR(3P) β the POSIX Programmer's Manual glow-up π
okay bestie, before we even get into it: this page lives in the POSIX Programmer's Manual, which is like the β¨officialβ¨ edition. but heads up β the Linux implementation of this interface may differ, so go check the corresponding Linux manual page for the actual Linux tea. or, plot twist, the interface might not even be implemented on Linux at all. π read the room before you ship.
πΈ NAME πΈ
seekdir β set the position of a directory stream. that's it. that's the whole vibe. move the little cursor in your directory stream, queen.
β¨ SYNOPSIS β¨
#include <dirent.h>
void seekdir(DIR *dirp, long loc);
like, copy it exactly, don't freestyle it. π
π¦ DESCRIPTION π¦
so here's the deal, bestie. seekdir() sets the position of the next readdir() operation on the directory stream you pass in as dirp to the position you pass in as loc. teleporting the little reading finger, basically.
and here's the important part β the value of loc should have been returned from an earlier call to telldir() using the same directory stream. no borrowing locs from other streams, that's not the vibe. the new position reverts to the one associated with the directory stream when telldir() was performed. it's giving "rewind to the bookmark you saved."
π¨ okay so if the value oflocwas not obtained from an earlier call totelldir(), or if a call torewinddir()happened in between thetelldir()call and theseekdir()call, then the results of subsequent calls toreaddir()are unspecified. unspecified!! that's the scary one!! don't do it. periodt. π
π RETURN VALUE π
seekdir() shall not return a value. it's a void function, it gives you nothing back, it just does the thing. no return, no problem.
π ERRORS π
no errors are defined. zero. none. the error section is on vacation.
oh and btw β the following sections are informative. that's manpage-speak for "the real rules are above, this is just the commentary track." π
π EXAMPLES π
None.
like literally none, bestie. nothing here. moving on. π§
πΈ APPLICATION USAGE πΈ
None.
also nothing!! two empty sections in a row, iconic honestly. π
π RATIONALE π
okay this is the lore section, sit down. β
the original standard developers perceived that there were restrictions on the use of the seekdir() and telldir() functions related to implementation details, and for that reason these functions need not be supported on all POSIX-conforming systems. they are required on implementations supporting the XSI option, though. so like, depends where you're living.
one of the perceived problems of implementation is that returning to a given point in a directory is quite difficult to describe formally, in spite of its intuitive appeal, when systems that use B-trees, hashing functions, or other similar mechanisms to order their directories are considered. imagine trying to write a formal spec for "go back to where you were" when the directory is a hash table. nightmare fuel.
the definition of seekdir() and telldir() does not specify whether, when using these interfaces, a given directory entry will be seen at all, or more than once. so... maybe you see it, maybe you don't, maybe you see it twice. bestie it's a mystery box. π₯
on systems not supporting these functions, their capability can sometimes be accomplished by saving a filename found by readdir() and later using rewinddir() and a loop on readdir() to relocate the position from which the filename was saved. DIY seekdir, we love a workaround. π«Ά
β FUTURE DIRECTIONS β
None.
the future is empty and honestly? peaceful.
π₯ SEE ALSO π₯
fdopendir()readdir()telldir()
and the Base Definitions volume of POSIX.1β2017, <dirent.h>, <sys_types.h> β go read those if you want the full extended universe. π
π COPYRIGHT π
okay legal bestie moment, don't skip this:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, babe π
this one's from IEEE/The Open Group, 2017, and it's the SEEKDIR(3P) page β so go forth, save your locs, never call rewinddir() in between, and slay. πβ¨π¦
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms