This is an archive of the discontinued LLVM Phabricator instance.

[libc] add fileno function for Linux
Needs ReviewPublic

Authored by alfredfo on Aug 13 2023, 11:40 AM.

Details

Diff Detail

Event Timeline

alfredfo created this revision.Aug 13 2023, 11:40 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 13 2023, 11:40 AM
alfredfo requested review of this revision.Aug 13 2023, 11:40 AM
michaelrj added inline comments.Aug 14 2023, 10:18 AM
libc/src/stdio/fileno.cpp
3

nit: line formatting

alfredfo updated this revision to Diff 550073.Aug 14 2023, 1:53 PM

fix format

sivachandra added inline comments.
libc/config/linux/x86_64/entrypoints.txt
430

Can we add this to the other configs also?

libc/src/stdio/fileno.cpp
19

This is not a fully evolved API yet. For example, the Linux implementation does not try to check if stream is actually a file stream. But, we have not yet decided if the get_fileno should be responsible to perform that check, or if it is the job of this function to perform that check. It feels like we should have some kind of flag maintained in the File data structure to indicate whether stream has a number or not. Let me think about this and get back. If you have any better suggestions to make, feel free to share.

alfredfo updated this revision to Diff 550458.Aug 15 2023, 1:45 PM

add tests

@sivachandra: Yes, I also wondered about that (re: "Linux implementation does not try to check if stream is actually a file stream"). I don't know what the best solution is. I tried both glibc and llvm-libc with invalid stream as argument and both crashed. Seems like musl libc also just assumes that the file ptr is valid https://elixir.bootlin.com/musl/latest/source/src/stdio/fileno.c#L7

alfredfo added inline comments.Aug 15 2023, 1:53 PM
libc/config/linux/x86_64/entrypoints.txt
430

do you mean in config/linux/*every arch that works*/entrypoints.txt ? The get_fileno function is currently only implemented for Linux.