[libc][NFC] Move aligned access implementations to separate header
[llvm-project.git] / libc / src / spawn / posix_spawn_file_actions_adddup2.cpp
blobca18629ba6832f7d00904bfe8c9cf39def529845
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"
15 #include <errno.h>
16 #include <spawn.h>
18 namespace __llvm_libc {
20 LLVM_LIBC_FUNCTION(int, posix_spawn_file_actions_adddup2,
21 (posix_spawn_file_actions_t * actions, int fd, int newfd)) {
22 if (actions == nullptr)
23 return EINVAL;
24 if (fd < 0 || newfd < 0)
25 return EBADF;
27 AllocChecker ac;
28 auto *act = new (ac) SpawnFileDup2Action(fd, newfd);
29 if (!ac)
30 return ENOMEM;
31 BaseSpawnFileAction::add_action(actions, act);
33 return 0;
36 } // namespace __llvm_libc