telldir(3)
π telldir(3) β the bestie who tells you exactly where you're at π
okay so this one lives in the Library Functions Manual and it's genuinely such a little icon. it's giving "where am I in this directory stream bestie" and honestly? we love that for us. π«Ά
β¨ NAME β¨
telldir β return current location in directory stream π
π LIBRARY π
Standard C library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <dirent.h>
long telldir(DIR *dirp);
π§ Feature Test Macro Requirements for glibc (peep feature_test_macros(7))
telldir():
_XOPEN_SOURCE
|| /* glibc >= 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
π DESCRIPTION π
So telldir() hands you back the current location that's associated with the directory stream dirp. That's it. That's the whole vibe. A little receipt for where you are. π§Ύβ¨
π RETURN VALUE π
When it's slaying (success), telldir() returns the current location inside the directory stream. π
When it's not (error), you get -1 back, and errno gets set to tell you what went wrong. π
π ERRORS π
EBADFβ the directory stream descriptordirpis invalid. not a valid stream bestie, that's a no from me π
π ATTRIBUTES π
for the whole explanation of what these terms even mean, go see attributes(7) β iykyk.
- Interface:
telldir() - Attribute: Thread safety
- Value: MT-Safe π₯
β STANDARDS β
POSIX.1-2008. periodt. π
π¦ HISTORY π¦
POSIX.1-2001, 4.3BSD. it's been around, it's got lore. π
Up to glibc 2.1.1, the return type of telldir() was off_t. then POSIX.1-2001 came through and specified long, and that's the type that's been used since glibc 2.1.2. glow-up fr fr β¨
okay now the important part, listen up: in early filesystems, the value returned by telldir() was just a simple file offset within a directory. cute, simple, flat. BUT modern filesystems use tree or hash structures instead of flat tables to represent directories, and on those filesystems the value returned by telldir() (which also gets used internally by readdir(3)) is a "cookie" πͺ that the implementation uses to derive a position within the directory.
π¨ MAJOR WARNING π¨ Application programs should treat this strictly as an opaque value, making no assumptions about its contents. do not peek inside the cookie. do not decode the cookie. do not build your whole personality on guessing what the cookie means. just hold it and hand it back. π
π SEE ALSO π
closedir(3), opendir(3), readdir(3), rewinddir(3), scandir(3), seekdir(3)
and that's the whole page babes π this one came straight out of Linux man-pages 6.20, dated 2026-02-08 β go off, telldir(3), you opaque little cookie queen πͺππ«Ά
π¦ where this page comes from
- 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 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms