[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / libc / src / spawn / posix_spawn_file_actions_adddup2.cpp
blob710063d52e74dda81e7d3c77000d3320d4945b4b
1 //===-- Implementation of posix_spawn_file_actions_adddup2 ----------------===//
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 "posix_spawn_file_actions_adddup2.h"
11 #include "file_actions.h"
12 #include "src/__support/CPP/new.h"
13 #include "src/__support/common.h"
14 #include "src/__support/macros/config.h"
15 #include "src/errno/libc_errno.h"
17 #include <spawn.h>
19 namespace LIBC_NAMESPACE_DECL {
21 LLVM_LIBC_FUNCTION(int, posix_spawn_file_actions_adddup2,
22 (posix_spawn_file_actions_t * actions, int fd, int newfd)) {
23 if (actions == nullptr)
24 return EINVAL;
25 if (fd < 0 || newfd < 0)
26 return EBADF;
28 AllocChecker ac;
29 auto *act = new (ac) SpawnFileDup2Action(fd, newfd);
30 if (!ac)
31 return ENOMEM;
32 BaseSpawnFileAction::add_action(actions, act);
34 return 0;
37 } // namespace LIBC_NAMESPACE_DECL