[libc] `fileno` doesn't properly handle descriptorless streams.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Currently `fileno` doesn't properly handle `FILE` objects that aren't linux files. Specifically if you call `fileno` on a file from [`fopencookie`](https://github.com/llvm/llvm-project/blob/main/libc/src/stdio/fopencookie.cpp) or [`fmemopen`](https://github.com/llvm/llvm-project/blob/main/libc/src/stdio/fmemopen.cpp) it will blindly cast to [`LinuxFile`](https://github.com/llvm/llvm-project/blob/main/libc/src/__support/File/linux/file.cpp#L308) and try to read its file descriptor. POSIX says that this should return `EBADF`: https://pubs.opengroup.org/onlinepubs/9799919799/functions/fileno.html.
Ideally the solution wouldn't involve adding fake file descriptors to `CookieFile` or `MemoryFile`. Consider if there's a way to positively identify a file as a `LinuxFile` instead.
Contributor guide
Assessment
This issue has not been assessed yet.