• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Implementation of posix_spawn_file_actions_addclose ---------------===//
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 //===----------------------------------------------------------------------===//
8 
9 #include "posix_spawn_file_actions_addclose.h"
10 
11 #include "file_actions.h"
12 #include "src/__support/CPP/new.h"
13 #include "src/__support/common.h"
14 
15 #include <errno.h>
16 #include <spawn.h>
17 
18 namespace LIBC_NAMESPACE {
19 
20 LLVM_LIBC_FUNCTION(int, posix_spawn_file_actions_addclose,
21                    (posix_spawn_file_actions_t *__restrict actions, int fd)) {
22   if (actions == nullptr)
23     return EINVAL;
24   if (fd < 0)
25     return EBADF;
26 
27   AllocChecker ac;
28   auto *act = new (ac) SpawnFileCloseAction(fd);
29   if (!ac)
30     return ENOMEM;
31   BaseSpawnFileAction::add_action(actions, act);
32 
33   return 0;
34 }
35 
36 } // namespace LIBC_NAMESPACE
37