[AMDGPU][True16][CodeGen] true16 codegen pattern for v_med3_u/i16 (#121850)
[llvm-project.git] / libc / src / spawn / file_actions.h
blob80b92959c6a43a78152167b89f766785e3c3f5db
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 "src/__support/macros/config.h"
13 #include <spawn.h> // For mode_t
14 #include <stdint.h>
16 namespace LIBC_NAMESPACE_DECL {
18 struct BaseSpawnFileAction {
19 enum ActionType {
20 OPEN = 111,
21 CLOSE = 222,
22 DUP2 = 333,
25 ActionType type;
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);
32 back->next = act;
33 actions->__back = act;
34 } else {
35 // First action is being added.
36 actions->__front = actions->__back = act;
40 protected:
41 explicit BaseSpawnFileAction(ActionType t) : type(t), next(nullptr) {}
44 struct SpawnFileOpenAction : public BaseSpawnFileAction {
45 const char *path;
46 int fd;
47 int oflag;
48 mode_t mode;
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 {
56 int fd;
58 SpawnFileCloseAction(int fdesc)
59 : BaseSpawnFileAction(BaseSpawnFileAction::CLOSE), fd(fdesc) {}
62 struct SpawnFileDup2Action : public BaseSpawnFileAction {
63 int fd;
64 int newfd;
66 SpawnFileDup2Action(int fdesc, int new_fdesc)
67 : BaseSpawnFileAction(BaseSpawnFileAction::DUP2), fd(fdesc),
68 newfd(new_fdesc) {}
71 } // namespace LIBC_NAMESPACE_DECL
73 #endif // LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H