10#include "lldb/Host/Config.h"
12#include "llvm/Support/Errc.h"
13#include "llvm/Support/Errno.h"
27#include <Availability.h>
67#if defined(__OpenBSD__)
70 const bool cloexec = oflag & O_CLOEXEC;
77 return llvm::errorCodeToError(
78 std::error_code(errno, std::generic_category()));
81#if defined(__OpenBSD__)
82 if (cloexec && ::fcntl(
m_primary_fd, F_SETFD, FD_CLOEXEC) == -1) {
83 std::error_code EC(errno, std::generic_category());
85 return llvm::errorCodeToError(EC);
91 std::error_code EC(errno, std::generic_category());
93 return llvm::errorCodeToError(EC);
98 std::error_code EC(errno, std::generic_category());
100 return llvm::errorCodeToError(EC);
103 return llvm::Error::success();
105 return llvm::errorCodeToError(llvm::errc::not_supported);
115 return llvm::Error::success();
117 return llvm::errorCodeToError(
118 std::error_code(errno, std::generic_category()));
121#if !HAVE_PTSNAME_R || defined(__APPLE__)
123 static std::mutex mutex;
124 std::lock_guard<std::mutex> guard(mutex);
126 assert(r !=
nullptr);
134#if defined(__APPLE__)
135 if (__builtin_available(macos 10.13.4, iOS 11.3, tvOS 11.3, watchOS 4.4, *)) {
143#if defined(__APPLE__)
156 return std::move(Err);
160 return llvm::errorCodeToError(
161 std::error_code(errno, std::generic_category()));
172 return std::move(Err);
178#if defined(TIOCSCTTY)
181 return llvm::errorCodeToError(
182 std::error_code(errno, std::generic_category()));
186 for (
int fd : {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) {
188 return llvm::errorCodeToError(
189 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)