This is an archive of the discontinued LLVM Phabricator instance.

[libc] add scanf system file support
Needs ReviewPublic

Authored by michaelrj on May 4 2023, 2:26 PM.

Details

Reviewers
sivachandra
lntue
Summary

This patch is similar to the patch adding system file support to printf:
https://reviews.llvm.org/D146001. It also modifies the file reader
slightly to check for errors when ungetc is called.

Diff Detail

Event Timeline

michaelrj created this revision.May 4 2023, 2:26 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 4 2023, 2:26 PM
michaelrj requested review of this revision.May 4 2023, 2:26 PM
mcgrathr added inline comments.May 4 2023, 3:12 PM
libc/src/stdio/fscanf.cpp
21

This is rather different from what I was expecting. I hadn't seen D146001 before now, so I was thinking of the integration with FILE or whatever other underlying i/o mechanism as being entirely provided by the integrator. It's not clear to me if we have full parity here between the printf and scanf cores. That seems desirable, i.e. that a purely abstract interface can be filled out unrelated to anybody's concept of a FILE type, for the i/o interactions that the core needs. For integrating with a particular stdio implementation, it's not clear whether using the public stdio interfaces will be what's most desirable. The integrator should be able to write things up to their own internals, whether or not those look at all like what you presume stdio looks like.

35

ISTM that the integrator-provided template instantiations should be responsible for FILE*->FileT* rather than presuming that a reinterpret_cast here is safe and correct.

libc/src/stdio/scanf_core/vfscanf_internal.h