summaryrefslogtreecommitdiff
path: root/libc/src/stdio/printf_core/printf_main.h
diff options
context:
space:
mode:
authorMarcell Leleszi <59964679+mleleszi@users.noreply.github.com>2025-11-05 22:09:53 +0100
committerGitHub <noreply@github.com>2025-11-05 16:09:53 -0500
commit9e2f73fe9052a4fbf382a06e30b2441c6d99fb7e (patch)
tree11614f6da54c34910716d93077371d10f104ba66 /libc/src/stdio/printf_core/printf_main.h
parent54190970cf275fd1d8a99b7c84a6a106fd543c3d (diff)
[libc] Add printf error handling (with fixes #2) (#166517)
https://github.com/llvm/llvm-project/issues/159474 Another try of trying to land https://github.com/llvm/llvm-project/pull/166382 - Fix some leftover tests checking for specific errnos - Guard errno checking tests to not run on the GPU @michaelrj-google
Diffstat (limited to 'libc/src/stdio/printf_core/printf_main.h')
-rw-r--r--libc/src/stdio/printf_core/printf_main.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/libc/src/stdio/printf_core/printf_main.h b/libc/src/stdio/printf_core/printf_main.h
index 57f29858d529..1c7a7237c097 100644
--- a/libc/src/stdio/printf_core/printf_main.h
+++ b/libc/src/stdio/printf_core/printf_main.h
@@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H
#include "src/__support/arg_list.h"
+#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include "src/stdio/printf_core/converter.h"
#include "src/stdio/printf_core/core_structs.h"
@@ -22,8 +23,9 @@ namespace LIBC_NAMESPACE_DECL {
namespace printf_core {
template <WriteMode write_mode>
-int printf_main(Writer<write_mode> *writer, const char *__restrict str,
- internal::ArgList &args) {
+ErrorOr<size_t> printf_main(Writer<write_mode> *writer,
+ const char *__restrict str,
+ internal::ArgList &args) {
Parser<internal::ArgList> parser(str, args);
int result = 0;
for (FormatSection cur_section = parser.get_next_section();
@@ -33,9 +35,8 @@ int printf_main(Writer<write_mode> *writer, const char *__restrict str,
result = convert(writer, cur_section);
else
result = writer->write(cur_section.raw_string);
-
if (result < 0)
- return result;
+ return Error(-result);
}
return writer->get_chars_written();