brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · c69640a Raw
74 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H10#define LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H11 12#include "hdr/stdint_proxy.h"13#include "src/__support/macros/config.h"14#include <spawn.h> // For mode_t15 16namespace LIBC_NAMESPACE_DECL {17 18struct BaseSpawnFileAction {19  enum ActionType {20    OPEN = 111,21    CLOSE = 222,22    DUP2 = 333,23  };24 25  ActionType type;26  BaseSpawnFileAction *next;27 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;37    }38  }39 40protected:41  explicit BaseSpawnFileAction(ActionType t) : type(t), next(nullptr) {}42};43 44struct SpawnFileOpenAction : public BaseSpawnFileAction {45  const char *path;46  int fd;47  int oflag;48  mode_t mode;49 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) {}53};54 55struct SpawnFileCloseAction : public BaseSpawnFileAction {56  int fd;57 58  SpawnFileCloseAction(int fdesc)59      : BaseSpawnFileAction(BaseSpawnFileAction::CLOSE), fd(fdesc) {}60};61 62struct SpawnFileDup2Action : public BaseSpawnFileAction {63  int fd;64  int newfd;65 66  SpawnFileDup2Action(int fdesc, int new_fdesc)67      : BaseSpawnFileAction(BaseSpawnFileAction::DUP2), fd(fdesc),68        newfd(new_fdesc) {}69};70 71} // namespace LIBC_NAMESPACE_DECL72 73#endif // LLVM_LIBC_SRC_SPAWN_FILE_ACTIONS_H74