9 #include <mach-o/dyld.h>
14 char buffer[512] = {};
15 strerror_r(code, buffer,
sizeof(buffer));
20 int flags = fcntl(fd, F_GETFL, 0);
22 if (bNonBlocking) flags2 |= O_NONBLOCK;
23 else flags2 &= ~O_NONBLOCK;
24 if (flags2 != flags) fcntl(fd, F_SETFL, flags2);
28 int flags = fcntl(fd, F_GETFD);
30 if (bCloseOnExec) flags2 |= FD_CLOEXEC;
31 else flags2 &= ~FD_CLOEXEC;
32 if (flags != flags2) fcntl(fd, F_SETFD, flags2);
40 #if defined(__linux__) && defined(O_CLOEXEC)
41 if (pipe2(fd, bInheritable ? 0 : O_CLOEXEC) < 0)
throw exception_nix();
64 uint64_t temp = (uint64_t) floor( timeSeconds * 1000000.0 + 0.5);
65 tv.tv_usec = (uint32_t) (temp % 1000000);
66 tv.tv_sec = (uint32_t) (temp / 1000000);
70 return (
double)in.tv_sec + (double)in.tv_usec / 1000000.0;
81 return FD_ISSET( fd, &
m_set ) != 0;
88 return Select( (timeval*) NULL );
91 if (timeOutSeconds < 0) {
119 return sel.
Select( timeOutSeconds ) > 0;
123 return sel.
Select( timeOutSeconds ) > 0;
147 if (
read(
m_fd[0], &dummy, 1 ) != 1)
break;
156 return fdWaitRead( p_event, p_timeout_seconds );
162 int state = sel.
Select( timeout );
164 if (state == 0)
return 0;
165 if (sel.
Reads[ h1 ] )
return 1;
166 if (sel.
Reads[ h2 ] )
return 2;
180 gettimeofday(&tv, NULL);
188 ssize_t rv = (size_t) readlink(path, buffer.
get_ptr(), l);
189 if (rv < 0)
return false;
190 if ((
size_t)rv <= l) {
201 _NSGetExecutablePath(NULL, &len);
203 _NSGetExecutablePath(temp.
get_ptr(), &len);
207 return nixReadSymLink( strOut, PFC_string_formatter() <<
"/proc/" << (
unsigned) getpid() <<
"/exe");
213 randomData = open(
"/dev/random", O_RDONLY);
void read(const service_ptr_t< file > &p_file, abort_callback &p_abort, pfc::string_base &p_out, bool &is_utf8)
void setNonBlocking(int fd, bool bNonBlocking)
bool nixSelfProcessPath(string_base &strOut)
const t_item * get_ptr() const
void setCloseOnExec(int fd, bool bCloseOnExec)
void set_state(bool state)
void nixGetRandomData(void *outPtr, size_t outBytes)
void nixFormatError(string_base &str, int code)
bool nixReadSymLink(string_base &strOut, const char *path)
void max_acc(t_val &p_acc, const t_val &p_val)
void uSleepSeconds(double seconds, bool)
void set_size(t_size p_size)
bool fdWaitRead(int fd, double timeOutSeconds)
bool fdWaitWrite(int fd, double timeOutSeconds)
void write(const service_ptr_t< file > &p_file, abort_callback &p_abort, const char *p_string, bool is_utf8)
static int g_twoEventWait(nix_event &ev1, nix_event &ev2, double timeout)
timeval makeTimeVal(double timeSeconds)
void createPipe(int fd[2], bool bInheritable)
void setInheritable(int fd, bool bInheritable)
static bool g_wait_for(int p_event, double p_timeout_seconds)
void nixSleep(double seconds)
bool wait_for(double p_timeout_seconds)
double importTimeval(const timeval &in)