Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / stdio / scanf_core / reader.cpp
blobeca0e3784dc8d1744419ea1f9ae4a259d7b943b6
1 //===-- Reader definition 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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/scanf_core/reader.h"
10 #include <stddef.h>
12 namespace LIBC_NAMESPACE {
13 namespace scanf_core {
15 void Reader::ungetc(char c) {
16 --cur_chars_read;
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.
22 --(rb->buff_cur);
23 return;
25 stream_ungetc(static_cast<int>(c), input_stream);
27 } // namespace scanf_core
28 } // namespace LIBC_NAMESPACE