Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / libc / src / spawn / posix_spawn_file_actions_addopen.cpp
blob028d6e895f3c44938dddc0c9791f8e9ef74ad64c
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"
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_addopen,
22 (posix_spawn_file_actions_t *__restrict actions, int fd,
23 const char *__restrict path, int oflag, mode_t mode)) {
24 if (actions == nullptr)
25 return EINVAL;
26 if (fd < 0)
27 return EBADF;
29 AllocChecker ac;
30 auto *act = new (ac) SpawnFileOpenAction(path, fd, oflag, mode);
31 if (act == nullptr)
32 return ENOMEM;
33 BaseSpawnFileAction::add_action(actions, act);
35 return 0;
38 } // namespace LIBC_NAMESPACE_DECL