xref: /llvm-project/libc/src/stdio/setbuf.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
14eea8849SSiva Chandra Reddy //===-- Implementation of setbuf ------------------------------------------===//
24eea8849SSiva Chandra Reddy //
34eea8849SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44eea8849SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information.
54eea8849SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
64eea8849SSiva Chandra Reddy //
74eea8849SSiva Chandra Reddy //===----------------------------------------------------------------------===//
84eea8849SSiva Chandra Reddy 
94eea8849SSiva Chandra Reddy #include "src/stdio/setbuf.h"
105aed6d67SMichael Jones #include "hdr/stdio_macros.h"
114eea8849SSiva Chandra Reddy #include "src/__support/File/file.h"
12*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1304a9c625SMichael Jones #include "src/errno/libc_errno.h"
144eea8849SSiva Chandra Reddy 
15*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
164eea8849SSiva Chandra Reddy 
174eea8849SSiva Chandra Reddy LLVM_LIBC_FUNCTION(void, setbuf,
184eea8849SSiva Chandra Reddy                    (::FILE *__restrict stream, char *__restrict buf)) {
194eea8849SSiva Chandra Reddy   int mode = _IOFBF;
204eea8849SSiva Chandra Reddy   if (buf == nullptr)
214eea8849SSiva Chandra Reddy     mode = _IONBF;
22b6bc9d72SGuillaume Chatelet   int err = reinterpret_cast<LIBC_NAMESPACE::File *>(stream)->set_buffer(
234eea8849SSiva Chandra Reddy       buf, BUFSIZ, mode);
244eea8849SSiva Chandra Reddy   if (err != 0)
2504a9c625SMichael Jones     libc_errno = err;
264eea8849SSiva Chandra Reddy }
274eea8849SSiva Chandra Reddy 
28*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
29