Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / spawn / file_actions.h
blob7113256bf49cb749a3eac9bbd52e0996282cc301
1 //===-- Spawn file actions -------------------------------------*- C++ -*-===//
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 #ifndef LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H
10 #define LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H
12 #include <spawn.h> // For mode_t
13 #include <stdint.h>
15 namespace LIBC_NAMESPACE {
17 struct BaseSpawnFileAction {
18 enum ActionType {
19 OPEN = 111,
20 CLOSE = 222,
21 DUP2 = 333,
24 ActionType type;
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);
31 back->next = act;
32 actions->__back = act;
33 } else {
34 // First action is being added.
35 actions->__front = actions->__back = act;
39 protected:
40 explicit BaseSpawnFileAction(ActionType t) : type(t), next(nullptr) {}
43 struct SpawnFileOpenAction : public BaseSpawnFileAction {
44 const char *path;
45 int fd;
46 int oflag;
47 mode_t mode;
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 {
55 int fd;
57 SpawnFileCloseAction(int fdesc)
58 : BaseSpawnFileAction(BaseSpawnFileAction::CLOSE), fd(fdesc) {}
61 struct SpawnFileDup2Action : public BaseSpawnFileAction {
62 int fd;
63 int newfd;
65 SpawnFileDup2Action(int fdesc, int new_fdesc)
66 : BaseSpawnFileAction(BaseSpawnFileAction::DUP2), fd(fdesc),
67 newfd(new_fdesc) {}
70 } // namespace LIBC_NAMESPACE
72 #endif // LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H