52 lines · c
1//===-- Pointer specifier converter for scanf -------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_STDIO_SCANF_CORE_PTR_CONVERTER_H10#define LLVM_LIBC_SRC_STDIO_SCANF_CORE_PTR_CONVERTER_H11 12#include "src/__support/ctype_utils.h"13#include "src/__support/macros/config.h"14#include "src/stdio/scanf_core/core_structs.h"15#include "src/stdio/scanf_core/int_converter.h"16#include "src/stdio/scanf_core/reader.h"17 18#include <stddef.h>19 20namespace LIBC_NAMESPACE_DECL {21namespace scanf_core {22 23template <typename T>24int convert_pointer(Reader<T> *reader, const FormatSection &to_conv) {25 static const char nullptr_string[] = "(nullptr)";26 27 // Check if it's exactly the nullptr string, if so then it's a nullptr.28 char cur_char = reader->getc();29 size_t i = 0;30 for (; i < (sizeof(nullptr_string) - 1) &&31 internal::tolower(cur_char) == nullptr_string[i];32 ++i) {33 cur_char = reader->getc();34 }35 if (i == (sizeof(nullptr_string) - 1)) {36 *reinterpret_cast<void **>(to_conv.output_ptr) = nullptr;37 return READ_OK;38 } else if (i > 0) {39 return MATCHING_FAILURE;40 }41 42 reader->ungetc(cur_char);43 44 // Else treat it as a hex int45 return convert_int(reader, to_conv);46}47 48} // namespace scanf_core49} // namespace LIBC_NAMESPACE_DECL50 51#endif // LLVM_LIBC_SRC_STDIO_SCANF_CORE_PTR_CONVERTER_H52