Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | //===-- Write integer Converter for printf ----------------------*- C++ -*-===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_WRITE_INT_CONVERTER_H |
| 10 | #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_WRITE_INT_CONVERTER_H |
| 11 | |
| 12 | #include "src/__support/macros/config.h" |
| 13 | #include "src/stdio/printf_core/core_structs.h" |
| 14 | #include "src/stdio/printf_core/writer.h" |
| 15 | |
| 16 | #include <inttypes.h> |
| 17 | #include <stddef.h> |
| 18 | |
| 19 | namespace LIBC_NAMESPACE_DECL { |
| 20 | namespace printf_core { |
| 21 | |
| 22 | template <WriteMode write_mode> |
| 23 | LIBC_INLINE int convert_write_int(Writer<write_mode> *writer, |
| 24 | const FormatSection &to_conv) { |
| 25 | |
| 26 | #ifndef LIBC_COPT_PRINTF_NO_NULLPTR_CHECKS |
| 27 | // This is an additional check added by LLVM-libc. |
| 28 | if (to_conv.conv_val_ptr == nullptr) |
| 29 | return NULLPTR_WRITE_ERROR; |
| 30 | #endif // LIBC_COPT_PRINTF_NO_NULLPTR_CHECKS |
| 31 | |
| 32 | int written = writer->get_chars_written(); |
| 33 | |
| 34 | switch (to_conv.length_modifier) { |
| 35 | case LengthModifier::none: |
| 36 | *reinterpret_cast<int *>(to_conv.conv_val_ptr) = written; |
| 37 | break; |
| 38 | case LengthModifier::l: |
| 39 | *reinterpret_cast<long *>(to_conv.conv_val_ptr) = written; |
| 40 | break; |
| 41 | case LengthModifier::ll: |
| 42 | case LengthModifier::L: |
| 43 | *reinterpret_cast<long long *>(to_conv.conv_val_ptr) = written; |
| 44 | break; |
| 45 | case LengthModifier::h: |
| 46 | *reinterpret_cast<short *>(to_conv.conv_val_ptr) = |
| 47 | static_cast<short>(written); |
| 48 | break; |
| 49 | case LengthModifier::hh: |
| 50 | *reinterpret_cast<signed char *>(to_conv.conv_val_ptr) = |
| 51 | static_cast<signed char>(written); |
| 52 | break; |
| 53 | case LengthModifier::z: |
| 54 | *reinterpret_cast<size_t *>(to_conv.conv_val_ptr) = written; |
| 55 | break; |
| 56 | case LengthModifier::t: |
| 57 | *reinterpret_cast<ptrdiff_t *>(to_conv.conv_val_ptr) = written; |
| 58 | break; |
| 59 | case LengthModifier::j: |
| 60 | case LengthModifier::w: |
| 61 | case LengthModifier::wf: |
| 62 | *reinterpret_cast<uintmax_t *>(to_conv.conv_val_ptr) = written; |
| 63 | break; |
| 64 | } |
| 65 | return WRITE_OK; |
| 66 | } |
| 67 | |
| 68 | } // namespace printf_core |
| 69 | } // namespace LIBC_NAMESPACE_DECL |
| 70 | |
| 71 | #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_WRITE_INT_CONVERTER_H |
| 72 |
Warning: This file is not a C or C++ file. It does not have highlighting.
