xref: /aosp_15_r20/external/llvm-libc/src/stdio/setvbuf.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- Implementation of setvbuf -----------------------------------------===//
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/setvbuf.h"
10 #include "src/__support/File/file.h"
11 
12 #include "hdr/types/FILE.h"
13 #include "src/__support/macros/config.h"
14 #include "src/errno/libc_errno.h"
15 #include <stddef.h>
16 
17 namespace LIBC_NAMESPACE_DECL {
18 
19 LLVM_LIBC_FUNCTION(int, setvbuf,
20                    (::FILE *__restrict stream, char *__restrict buf, int type,
21                     size_t size)) {
22   int err = reinterpret_cast<LIBC_NAMESPACE::File *>(stream)->set_buffer(
23       buf, size, type);
24   if (err != 0)
25     libc_errno = err;
26   return err;
27 }
28 
29 } // namespace LIBC_NAMESPACE_DECL
30