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 <spawn.h> // For mode_t
15 namespace LIBC_NAMESPACE
{
17 struct BaseSpawnFileAction
{
25 BaseSpawnFileAction
*next
;
27 static void add_action(posix_spawn_file_actions_t
*actions
,
28 BaseSpawnFileAction
*act
) {
29 if (actions
->__back
!= nullptr) {
30 auto *back
= reinterpret_cast<BaseSpawnFileAction
*>(actions
->__back
);
32 actions
->__back
= act
;
34 // First action is being added.
35 actions
->__front
= actions
->__back
= act
;
40 explicit BaseSpawnFileAction(ActionType t
) : type(t
), next(nullptr) {}
43 struct SpawnFileOpenAction
: public BaseSpawnFileAction
{
49 SpawnFileOpenAction(const char *p
, int fdesc
, int flags
, mode_t m
)
50 : BaseSpawnFileAction(BaseSpawnFileAction::OPEN
), path(p
), fd(fdesc
),
51 oflag(flags
), mode(m
) {}
54 struct SpawnFileCloseAction
: public BaseSpawnFileAction
{
57 SpawnFileCloseAction(int fdesc
)
58 : BaseSpawnFileAction(BaseSpawnFileAction::CLOSE
), fd(fdesc
) {}
61 struct SpawnFileDup2Action
: public BaseSpawnFileAction
{
65 SpawnFileDup2Action(int fdesc
, int new_fdesc
)
66 : BaseSpawnFileAction(BaseSpawnFileAction::DUP2
), fd(fdesc
),
70 } // namespace LIBC_NAMESPACE
72 #endif // LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H