10#include "lldb/Host/Config.h"
12#include "llvm/Support/Errc.h"
13#include "llvm/Support/Errno.h"
27#include <Availability.h>
70 return llvm::errorCodeToError(
71 std::error_code(errno, std::generic_category()));
76 std::error_code EC(errno, std::generic_category());
78 return llvm::errorCodeToError(EC);
83 std::error_code EC(errno, std::generic_category());
85 return llvm::errorCodeToError(EC);
88 return llvm::Error::success();
90 return llvm::errorCodeToError(llvm::errc::not_supported);
100 return llvm::Error::success();
102 return llvm::errorCodeToError(
103 std::error_code(errno, std::generic_category()));
106#if !HAVE_PTSNAME_R || defined(__APPLE__)
108 static std::mutex mutex;
109 std::lock_guard<std::mutex> guard(mutex);
111 assert(r !=
nullptr);
119#if defined(__APPLE__)
120 if (__builtin_available(macos 10.13.4, iOS 11.3, tvOS 11.3, watchOS 4.4, *)) {
128#if defined(__APPLE__)
141 return std::move(Err);
145 return llvm::errorCodeToError(
146 std::error_code(errno, std::generic_category()));
157 return std::move(Err);
163#if defined(TIOCSCTTY)
166 return llvm::errorCodeToError(
167 std::error_code(errno, std::generic_category()));
171 for (
int fd : {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) {
173 return llvm::errorCodeToError(
174 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()
Constructs this object with invalid primary and secondary file descriptors.
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.
void Reset()
Close both file descriptors and clear cached state.
@ invalid_fd
Invalid file descriptor value.
int GetPrimaryFileDescriptor() const
The primary file descriptor accessor.
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
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()
The destructor will close the primary and secondary file descriptor/HANDLEs if they are valid and own...
#define UNUSED_IF_ASSERT_DISABLED(x)
A class that represents a running process on the host machine.
int posix_openpt(int flag)