summaryrefslogtreecommitdiff
path: root/libc/src/stdio/printf_core/vfprintf_internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'libc/src/stdio/printf_core/vfprintf_internal.h')
-rw-r--r--libc/src/stdio/printf_core/vfprintf_internal.h41
1 files changed, 13 insertions, 28 deletions
diff --git a/libc/src/stdio/printf_core/vfprintf_internal.h b/libc/src/stdio/printf_core/vfprintf_internal.h
index 564441d3bf51..630de9d9d43d 100644
--- a/libc/src/stdio/printf_core/vfprintf_internal.h
+++ b/libc/src/stdio/printf_core/vfprintf_internal.h
@@ -11,7 +11,6 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
-#include "src/__support/error_or.h"
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
#include "src/__support/macros/config.h"
#include "src/stdio/printf_core/core_structs.h"
@@ -36,8 +35,8 @@ LIBC_INLINE void funlockfile(FILE *f) {
reinterpret_cast<LIBC_NAMESPACE::File *>(f)->unlock();
}
-LIBC_INLINE FileIOResult fwrite_unlocked(const void *ptr, size_t size,
- size_t nmemb, FILE *f) {
+LIBC_INLINE size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb,
+ FILE *f) {
return reinterpret_cast<LIBC_NAMESPACE::File *>(f)->write_unlocked(
ptr, size * nmemb);
}
@@ -48,11 +47,9 @@ LIBC_INLINE void flockfile(::FILE *f) { ::flockfile(f); }
LIBC_INLINE void funlockfile(::FILE *f) { ::funlockfile(f); }
-LIBC_INLINE FileIOResult fwrite_unlocked(const void *ptr, size_t size,
- size_t nmemb, ::FILE *f) {
- // Need to use system errno in this case, as system write will set this errno
- // which we need to propagate back into our code.
- return {::fwrite_unlocked(ptr, size, nmemb, f), errno};
+LIBC_INLINE size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb,
+ ::FILE *f) {
+ return ::fwrite_unlocked(ptr, size, nmemb, f);
}
#endif // LIBC_COPT_STDIO_USE_SYSTEM_FILE
} // namespace internal
@@ -63,38 +60,26 @@ LIBC_INLINE int file_write_hook(cpp::string_view new_str, void *fp) {
::FILE *target_file = reinterpret_cast<::FILE *>(fp);
// Write new_str to the target file. The logic preventing a zero-length write
// is in the writer, so we don't check here.
- auto write_result = internal::fwrite_unlocked(new_str.data(), sizeof(char),
- new_str.size(), target_file);
- // Propagate actual system error in FileIOResult.
- if (write_result.has_error())
- return -write_result.error;
-
- // In case short write occured or error was not set on FileIOResult for some
- // reason.
- if (write_result.value != new_str.size() ||
- internal::ferror_unlocked(target_file))
+ size_t written = internal::fwrite_unlocked(new_str.data(), sizeof(char),
+ new_str.size(), target_file);
+ if (written != new_str.size() || internal::ferror_unlocked(target_file))
return FILE_WRITE_ERROR;
-
return WRITE_OK;
}
-LIBC_INLINE ErrorOr<size_t> vfprintf_internal(::FILE *__restrict stream,
- const char *__restrict format,
- internal::ArgList &args) {
+LIBC_INLINE int vfprintf_internal(::FILE *__restrict stream,
+ const char *__restrict format,
+ internal::ArgList &args) {
constexpr size_t BUFF_SIZE = 1024;
char buffer[BUFF_SIZE];
printf_core::WriteBuffer<Mode<WriteMode::FLUSH_TO_STREAM>::value> wb(
buffer, BUFF_SIZE, &file_write_hook, reinterpret_cast<void *>(stream));
Writer writer(wb);
internal::flockfile(stream);
- auto retval = printf_main(&writer, format, args);
- if (!retval.has_value()) {
- internal::funlockfile(stream);
- return retval;
- }
+ int retval = printf_main(&writer, format, args);
int flushval = wb.overflow_write("");
if (flushval != WRITE_OK)
- retval = Error(-flushval);
+ retval = flushval;
internal::funlockfile(stream);
return retval;
}