xref: /llvm-project/libc/src/unistd/linux/pipe2.cpp (revision 6219c8083904b49d09f466b703ca47891f978278)
1*6219c808SDuncan //===-- Linux implementation of pipe --------------------------------------===//
2*6219c808SDuncan //
3*6219c808SDuncan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*6219c808SDuncan // See https://llvm.org/LICENSE.txt for license information.
5*6219c808SDuncan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*6219c808SDuncan //
7*6219c808SDuncan //===----------------------------------------------------------------------===//
8*6219c808SDuncan 
9*6219c808SDuncan #include "src/unistd/pipe2.h"
10*6219c808SDuncan 
11*6219c808SDuncan #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12*6219c808SDuncan #include "src/__support/common.h"
13*6219c808SDuncan #include "src/__support/macros/config.h"
14*6219c808SDuncan #include "src/errno/libc_errno.h"
15*6219c808SDuncan #include <sys/syscall.h> // For syscall numbers.
16*6219c808SDuncan 
17*6219c808SDuncan namespace LIBC_NAMESPACE_DECL {
18*6219c808SDuncan 
19*6219c808SDuncan LLVM_LIBC_FUNCTION(int, pipe2, (int pipefd[2], int flags)) {
20*6219c808SDuncan   int ret = LIBC_NAMESPACE::syscall_impl<int>(
21*6219c808SDuncan       SYS_pipe2, reinterpret_cast<long>(pipefd), flags);
22*6219c808SDuncan   if (ret < 0) {
23*6219c808SDuncan     libc_errno = -ret;
24*6219c808SDuncan     return -1;
25*6219c808SDuncan   }
26*6219c808SDuncan   MSAN_UNPOISON(pipefd, sizeof(int) * 2);
27*6219c808SDuncan   return ret;
28*6219c808SDuncan }
29*6219c808SDuncan 
30*6219c808SDuncan } // namespace LIBC_NAMESPACE_DECL
31