diff options
Diffstat (limited to 'libc/src/stdio/printf_core/vasprintf_internal.h')
| -rw-r--r-- | libc/src/stdio/printf_core/vasprintf_internal.h | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/libc/src/stdio/printf_core/vasprintf_internal.h b/libc/src/stdio/printf_core/vasprintf_internal.h index 41df17b67f35..283d8df2810f 100644 --- a/libc/src/stdio/printf_core/vasprintf_internal.h +++ b/libc/src/stdio/printf_core/vasprintf_internal.h @@ -10,7 +10,6 @@ #include "hdr/func/malloc.h" #include "hdr/func/realloc.h" #include "src/__support/arg_list.h" -#include "src/__support/error_or.h" #include "src/stdio/printf_core/core_structs.h" #include "src/stdio/printf_core/printf_main.h" #include "src/stdio/printf_core/writer.h" @@ -30,7 +29,7 @@ LIBC_INLINE int resize_overflow_hook(cpp::string_view new_str, void *target) { if (new_buff == nullptr) { if (wb->buff != wb->init_buff) free(wb->buff); - return ALLOCATION_ERROR; + return printf_core::ALLOCATION_ERROR; } if (isBuffOnStack) inline_memcpy(new_buff, wb->buff, wb->buff_cur); @@ -43,28 +42,27 @@ LIBC_INLINE int resize_overflow_hook(cpp::string_view new_str, void *target) { constexpr size_t DEFAULT_BUFFER_SIZE = 200; -LIBC_INLINE ErrorOr<size_t> vasprintf_internal(char **ret, - const char *__restrict format, - internal::ArgList args) { +LIBC_INLINE int vasprintf_internal(char **ret, const char *__restrict format, + internal::ArgList args) { char init_buff_on_stack[DEFAULT_BUFFER_SIZE]; printf_core::WriteBuffer<Mode<WriteMode::RESIZE_AND_FILL_BUFF>::value> wb( init_buff_on_stack, DEFAULT_BUFFER_SIZE, resize_overflow_hook); printf_core::Writer writer(wb); auto ret_val = printf_core::printf_main(&writer, format, args); - if (!ret_val.has_value()) { + if (ret_val < 0) { *ret = nullptr; - return ret_val; + return -1; } if (wb.buff == init_buff_on_stack) { - *ret = static_cast<char *>(malloc(ret_val.value() + 1)); + *ret = static_cast<char *>(malloc(ret_val + 1)); if (ret == nullptr) - return Error(ALLOCATION_ERROR); - inline_memcpy(*ret, wb.buff, ret_val.value()); + return printf_core::ALLOCATION_ERROR; + inline_memcpy(*ret, wb.buff, ret_val); } else { *ret = wb.buff; } - (*ret)[ret_val.value()] = '\0'; + (*ret)[ret_val] = '\0'; return ret_val; } } // namespace printf_core |
