brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 1f49bd2 Raw
80 lines · c
1//===-- PseudoTerminal.h ----------------------------------------*- 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//  Created by Greg Clayton on 1/8/08.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_PSEUDOTERMINAL_H14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_PSEUDOTERMINAL_H15 16#include <fcntl.h>17#include <string>18#include <termios.h>19 20class PseudoTerminal {21public:22  enum { invalid_fd = -1, invalid_pid = -1 };23 24  enum Status {25    success = 0,26    err_posix_openpt_failed = -2,27    err_grantpt_failed = -3,28    err_unlockpt_failed = -4,29    err_ptsname_failed = -5,30    err_open_secondary_failed = -6,31    err_fork_failed = -7,32    err_setsid_failed = -8,33    err_failed_to_acquire_controlling_terminal = -9,34    err_dup2_failed_on_stdin = -10,35    err_dup2_failed_on_stdout = -11,36    err_dup2_failed_on_stderr = -1237  };38  // Constructors and Destructors39  PseudoTerminal();40  ~PseudoTerminal();41 42  void ClosePrimary();43  void CloseSecondary();44  Status OpenFirstAvailablePrimary(int oflag);45  Status OpenSecondary(int oflag);46  int PrimaryFD() const { return m_primary_fd; }47  int SecondaryFD() const { return m_secondary_fd; }48  int ReleasePrimaryFD() {49    // Release ownership of the primary pseudo terminal file50    // descriptor without closing it. (the destructor for this51    // class will close it otherwise!)52    int fd = m_primary_fd;53    m_primary_fd = invalid_fd;54    return fd;55  }56  int ReleaseSecondaryFD() {57    // Release ownership of the secondary pseudo terminal file58    // descriptor without closing it (the destructor for this59    // class will close it otherwise!)60    int fd = m_secondary_fd;61    m_secondary_fd = invalid_fd;62    return fd;63  }64 65  const char *SecondaryName() const;66 67  pid_t Fork(Status &error);68 69protected:70  // Classes that inherit from PseudoTerminal can see and modify these71  int m_primary_fd;72  int m_secondary_fd;73 74private:75  PseudoTerminal(const PseudoTerminal &rhs) = delete;76  PseudoTerminal &operator=(const PseudoTerminal &rhs) = delete;77};78 79#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_PSEUDOTERMINAL_H80