1 //===-- Reader definition for scanf -----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/scanf_core/reader.h"
12 namespace LIBC_NAMESPACE
{
13 namespace scanf_core
{
15 void Reader::ungetc(char c
) {
17 if (rb
!= nullptr && rb
->buff_cur
> 0) {
18 // While technically c should be written back to the buffer, in scanf we
19 // always write the character that was already there. Additionally, the
20 // buffer is most likely to contain a string that isn't part of a file,
21 // which may not be writable.
25 stream_ungetc(static_cast<int>(c
), input_stream
);
27 } // namespace scanf_core
28 } // namespace LIBC_NAMESPACE