brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 9fa2ede Raw
40 lines · cpp
1//===-- Implementation of sscanf --------------------------------*- 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#include "src/stdio/sscanf.h"10 11#include "src/__support/CPP/limits.h"12#include "src/__support/arg_list.h"13#include "src/__support/macros/config.h"14#include "src/stdio/scanf_core/scanf_main.h"15#include "src/stdio/scanf_core/string_reader.h"16 17#include "hdr/stdio_macros.h"18#include "hdr/types/FILE.h"19#include <stdarg.h>20 21namespace LIBC_NAMESPACE_DECL {22 23LLVM_LIBC_FUNCTION(int, sscanf,24                   (const char *__restrict buffer,25                    const char *__restrict format, ...)) {26  va_list vlist;27  va_start(vlist, format);28  internal::ArgList args(vlist); // This holder class allows for easier copying29                                 // and pointer semantics, as well as handling30                                 // destruction automatically.31  va_end(vlist);32  scanf_core::StringReader reader(buffer, cpp::numeric_limits<size_t>::max());33  int ret_val = scanf_core::scanf_main(&reader, format, args);34  // This is done to avoid including stdio.h in the internals. On most systems35  // EOF is -1, so this will be transformed into just "return ret_val".36  return (ret_val == -1) ? EOF : ret_val;37}38 39} // namespace LIBC_NAMESPACE_DECL40