xref: /llvm-project/libc/src/stdio/setbuf.cpp (revision 5aed6d67e3f051262c67e3295476bf13cfc099c4)
1 //===-- Implementation of setbuf ------------------------------------------===//
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 #include "src/stdio/setbuf.h"
10 #include "hdr/stdio_macros.h"
11 #include "src/__support/File/file.h"
12 #include "src/errno/libc_errno.h"
13 
14 namespace LIBC_NAMESPACE {
15 
16 LLVM_LIBC_FUNCTION(void, setbuf,
17                    (::FILE *__restrict stream, char *__restrict buf)) {
18   int mode = _IOFBF;
19   if (buf == nullptr)
20     mode = _IONBF;
21   int err = reinterpret_cast<LIBC_NAMESPACE::File *>(stream)->set_buffer(
22       buf, BUFSIZ, mode);
23   if (err != 0)
24     libc_errno = err;
25 }
26 
27 } // namespace LIBC_NAMESPACE
28