# Support File Descriptors in os.readlink()

**URL:** <https://discuss.python.org/t/support-file-descriptors-in-os-readlink/109101>\
**Category:** Ideas\
**Created:** [September 17, 2026, 8:05pm UTC](https://discuss.python.org/t/support-file-descriptors-in-os-readlink/109101 "2026-09-17T20:05:58Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [September 18, 2026, 7:29am UTC](https://discuss.python.org/t/support-file-descriptors-in-os-readlink/109101/6 "2026-09-18T07:29:51Z")

</div>

> [@OOTS](#):
>
> Python probably just passes its arguments to the underlying syscall. I guess that more or less solves my issue on Linux (though I’d prefer a cleaner, documented and tested solution

The “passes its arguments to the underlying syscall” part is documented under [`dir_fd`](https://docs.python.org/3/library/os.html#dir-fd):

> For POSIX systems, Python will call the variant of the function with an `at` suffix and possibly prefixed with `f` (e.g. call `faccessat` instead of `access`).

So, your system docs apply; on Linux [`man 2 readlinkat`](https://www.man7.org/linux/man-pages/man2/readlink.2.html) should say:

> Since Linux 2.6.39, _path_ can be an empty string, in which case the  
> call operates on the symbolic link referred to by _dirfd_ (which  
> should have been obtained using `open(2)` with the `O_PATH` and  
> `O_NOFOLLOW` flags).

Unfortunately, `O_PATH` is Linux-specific and it makes the fd unusable for most other operations. I wouldn’t be comfortable adding `os.readlink` to [`os.supports_fd`](https://docs.python.org/3/library/os.html#os.supports_dir_fd) if it only supports `OS_PATH` fd’s.

> [@OOTS](#):
>
> On MacOS, you can call `freadlink()` (see [docs](https://www.macsyscalls.com/en/syscall/551-freadlink)).

+1. If you send a PR, ping me for review :‍)

> [@OOTS](#):
>
> I’d suggest to leave this feature unimplemented on Windows (raise an error when `os.readlink()` receives an integer, consistent with current behaviour).

Perfectly fine; `os.supports_fd` is already rather short on Windows.

---

_[View the full topic](https://discuss.python.org/t/support-file-descriptors-in-os-readlink/109101)._
