Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / spawn / posix_spawn_file_actions_addopen.cpp
blobc544f04bd54ae7f071866657c9cf9df60021f8c7
1 //===-- Implementation of posix_spawn_file_actions_addopen ----------------===//
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_addopen.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 LIBC_NAMESPACE {
20 LLVM_LIBC_FUNCTION(int, posix_spawn_file_actions_addopen,
21 (posix_spawn_file_actions_t *__restrict actions, int fd,
22 const char *__restrict path, int oflag, mode_t mode)) {
23 if (actions == nullptr)
24 return EINVAL;
25 if (fd < 0)
26 return EBADF;
28 AllocChecker ac;
29 auto *act = new (ac) SpawnFileOpenAction(path, fd, oflag, mode);
30 if (act == nullptr)
31 return ENOMEM;
32 BaseSpawnFileAction::add_action(actions, act);
34 return 0;
37 } // namespace LIBC_NAMESPACE