10#include "lldb/Host/Config.h"
12#include "llvm/Support/Errc.h"
13#include "llvm/Support/Errno.h"
27#include <Availability.h>
67 return llvm::errorCodeToError(
68 std::error_code(errno, std::generic_category()));
73 std::error_code EC(errno, std::generic_category());
75 return llvm::errorCodeToError(EC);
80 std::error_code EC(errno, std::generic_category());
82 return llvm::errorCodeToError(EC);
85 return llvm::Error::success();
87 return llvm::errorCodeToError(llvm::errc::not_supported);
97 return llvm::Error::success();
99 return llvm::errorCodeToError(
100 std::error_code(errno, std::generic_category()));
103#if !HAVE_PTSNAME_R || defined(__APPLE__)
105 static std::mutex mutex;
106 std::lock_guard<std::mutex> guard(mutex);
108 assert(r !=
nullptr);
116#if defined(__APPLE__)
117 if (__builtin_available(macos 10.13.4, iOS 11.3, tvOS 11.3, watchOS 4.4, *)) {
125#if defined(__APPLE__)
138 return std::move(Err);
142 return llvm::errorCodeToError(
143 std::error_code(errno, std::generic_category()));
154 return std::move(Err);
160#if defined(TIOCSCTTY)
163 return llvm::errorCodeToError(
164 std::error_code(errno, std::generic_category()));
168 for (
int fd : {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) {
170 return llvm::errorCodeToError(
171 std::error_code(errno, std::generic_category()));
static std::string use_ptsname(int fd)
int Open(const char *path, int flags, int mode=0600)
Wraps open in a platform-independent way.
static FileSystem & Instance()
PseudoTerminal()
Default constructor.
int m_secondary_fd
The file descriptor for the secondary.
int ReleaseSecondaryFileDescriptor()
Release the secondary file descriptor.
llvm::Error OpenFirstAvailablePrimary(int oflag)
Open the first available pseudo terminal.
llvm::Error OpenSecondary(int oflag)
Open the secondary for the current primary pseudo terminal.
void ClosePrimaryFileDescriptor()
Close the primary file descriptor if it is valid.
int m_primary_fd
The file descriptor for the primary.
llvm::Expected< lldb::pid_t > Fork()
Fork a child process that uses pseudo terminals for its stdio.
int GetPrimaryFileDescriptor() const
The primary file descriptor accessor.
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
@ invalid_fd
Invalid file descriptor value.
std::string GetSecondaryName() const
Get the name of the secondary pseudo terminal.
void CloseSecondaryFileDescriptor()
Close the secondary file descriptor if it is valid.
int GetSecondaryFileDescriptor() const
The secondary file descriptor accessor.
~PseudoTerminal()
Destructor.
#define UNUSED_IF_ASSERT_DISABLED(x)
A class that represents a running process on the host machine.
int posix_openpt(int flag)