Add support for macos
This commit is contained in:
parent
5659d5fdaf
commit
d892676121
|
@ -3,8 +3,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#if !defined(__linux__)
|
#if !defined(__linux__) && !defined(__APPLE__)
|
||||||
#error Only linux supported
|
#error Only linux and Macos supported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace cppshell {
|
namespace cppshell {
|
||||||
|
|
|
@ -2,7 +2,15 @@
|
||||||
#include <cppshell/utils/signals.hpp>
|
#include <cppshell/utils/signals.hpp>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
#include <wait.h>
|
#include <wait.h>
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#else
|
||||||
|
#error Supported only on Linux and Mac
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
|
@ -3,9 +3,12 @@
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
|
||||||
|
#if !defined(__APPLE__)
|
||||||
thread_local SigpipeState global_state;
|
thread_local SigpipeState global_state;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool IgnoreSigpipe() {
|
bool IgnoreSigpipe() {
|
||||||
|
#if !defined(__APPLE__)
|
||||||
sigset_t pending;
|
sigset_t pending;
|
||||||
sigemptyset(&pending);
|
sigemptyset(&pending);
|
||||||
sigpending(&pending);
|
sigpending(&pending);
|
||||||
|
@ -25,9 +28,12 @@ bool IgnoreSigpipe() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnignoreSigpipe() {
|
void UnignoreSigpipe() {
|
||||||
|
#if !defined(__APPLE__)
|
||||||
sigset_t pending;
|
sigset_t pending;
|
||||||
sigemptyset(&pending);
|
sigemptyset(&pending);
|
||||||
sigpending(&pending);
|
sigpending(&pending);
|
||||||
|
@ -47,4 +53,5 @@ void UnignoreSigpipe() {
|
||||||
if (global_state.sigpipe_unblock) {
|
if (global_state.sigpipe_unblock) {
|
||||||
pthread_sigmask(SIG_UNBLOCK, &sigpipe_mask, NULL);
|
pthread_sigmask(SIG_UNBLOCK, &sigpipe_mask, NULL);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue