1 //===-- Spawn file actions -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H
10 #define LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H
12 #include "src/__support/macros/config.h"
13 #include <spawn.h> // For mode_t
16 namespace LIBC_NAMESPACE_DECL
{
18 struct BaseSpawnFileAction
{
26 BaseSpawnFileAction
*next
;
28 static void add_action(posix_spawn_file_actions_t
*actions
,
29 BaseSpawnFileAction
*act
) {
30 if (actions
->__back
!= nullptr) {
31 auto *back
= reinterpret_cast<BaseSpawnFileAction
*>(actions
->__back
);
33 actions
->__back
= act
;
35 // First action is being added.
36 actions
->__front
= actions
->__back
= act
;
41 explicit BaseSpawnFileAction(ActionType t
) : type(t
), next(nullptr) {}
44 struct SpawnFileOpenAction
: public BaseSpawnFileAction
{
50 SpawnFileOpenAction(const char *p
, int fdesc
, int flags
, mode_t m
)
51 : BaseSpawnFileAction(BaseSpawnFileAction::OPEN
), path(p
), fd(fdesc
),
52 oflag(flags
), mode(m
) {}
55 struct SpawnFileCloseAction
: public BaseSpawnFileAction
{
58 SpawnFileCloseAction(int fdesc
)
59 : BaseSpawnFileAction(BaseSpawnFileAction::CLOSE
), fd(fdesc
) {}
62 struct SpawnFileDup2Action
: public BaseSpawnFileAction
{
66 SpawnFileDup2Action(int fdesc
, int new_fdesc
)
67 : BaseSpawnFileAction(BaseSpawnFileAction::DUP2
), fd(fdesc
),
71 } // namespace LIBC_NAMESPACE_DECL
73 #endif // LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H