This is an archive of the discontinued LLVM Phabricator instance.

[libc] add fprintf and file_writer
ClosedPublic

Authored by michaelrj on May 18 2022, 5:02 PM.

Details

Summary

This patch adds the file_writer header, which just provides a wrapper
for File->write, as well as fprintf to use it. There are no unit tests
for file_writer since it's too simple to need them, but fprintf does
have a simple test of writing to a file.

Diff Detail

Event Timeline

michaelrj created this revision.May 18 2022, 5:02 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 18 2022, 5:02 PM
michaelrj requested review of this revision.May 18 2022, 5:02 PM
sivachandra added inline comments.May 19 2022, 9:38 AM
libc/src/stdio/printf_core/file_writer.h
24

Is it OK to ignore the return value? For example, if file were read only, then write would fail. Shouldn't that be reflected in the fprintf return value?

michaelrj updated this revision to Diff 430793.May 19 2022, 1:32 PM
michaelrj marked an inline comment as done.

add handling for FILE errors

libc/src/stdio/printf_core/file_writer.h
24

I've added a check of the file's ferror status in fprintf and a section of the test to check that it works.

sivachandra accepted this revision.May 31 2022, 1:47 PM
sivachandra added inline comments.
libc/test/src/stdio/fprintf_test.cpp
29

Put this is a common constexpr char[].

32

Same here.

44

Instead of 37, use sizeof(...).

This revision is now accepted and ready to land.May 31 2022, 1:47 PM
michaelrj updated this revision to Diff 433182.May 31 2022, 1:57 PM
michaelrj marked 3 inline comments as done.

move to constexpr variables for test strings

michaelrj edited the summary of this revision. (Show Details)May 31 2022, 1:58 PM
This revision was landed with ongoing or failed builds.May 31 2022, 1:59 PM
This revision was automatically updated to reflect the committed changes.