19#include "qplatformdefs.h"
20#include <QtCore/private/qglobal_p.h>
25# error "qcore_unix_p.h included on a non-Unix system"
33#if !defined (Q_OS_VXWORKS)
34# if !defined(Q_OS_HPUX) || defined(__ia64)
35# include <sys/select.h>
39# include <selectLib.h>
47#if !defined(QT_POSIX_IPC) && !defined(QT_NO_SHAREDMEMORY) && !defined(Q_OS_ANDROID)
51#if defined(Q_OS_VXWORKS)
55#ifdef QT_NO_NATIVE_POLL
63#define EINTR_LOOP(var, cmd) \
66 } while (var == -1 && errno == EINTR)
72static constexpr auto OneSecAsNsecs = std::chrono::nanoseconds(std::chrono::seconds{ 1 }).
count();
76 using namespace std::chrono;
77 const seconds secs = duration_cast<seconds>(
timeout);
78 const nanoseconds frac =
timeout - secs;
80 ts.tv_sec = secs.count();
81 ts.tv_nsec = frac.count();
85template <
typename Duration>
88 using namespace std::chrono;
89 return duration_cast<Duration>(seconds{ts.tv_sec} + nanoseconds{ts.tv_nsec});
94 return timespecToChrono<std::chrono::milliseconds>(ts);
104 while (
t.tv_nsec < 0) {
111{
return t1.tv_sec <
t2.tv_sec || (
t1.tv_sec ==
t2.tv_sec &&
t1.tv_nsec <
t2.tv_nsec); }
113{
return t1.tv_sec ==
t2.tv_sec &&
t1.tv_nsec ==
t2.tv_nsec; }
115{
return !(
t1 ==
t2); }
118 t1.tv_sec +=
t2.tv_sec;
119 t1.tv_nsec +=
t2.tv_nsec;
125 tmp.tv_sec =
t1.tv_sec +
t2.tv_sec;
126 tmp.tv_nsec =
t1.tv_nsec +
t2.tv_nsec;
132 tmp.tv_sec =
t1.tv_sec - (
t2.tv_sec - 1);
139 tmp.tv_sec =
t1.tv_sec * mul;
140 tmp.tv_nsec =
t1.tv_nsec * mul;
146 tv.tv_sec = ts.tv_sec;
147 tv.tv_usec = ts.tv_nsec / 1000;
151inline timespec &
operator+=(timespec &
t1, std::chrono::milliseconds msecs)
159 t1 += std::chrono::milliseconds{ms};
163inline timespec
operator+(
const timespec &
t1, std::chrono::milliseconds msecs)
172 return t1 + std::chrono::milliseconds{ms};
178 ts.tv_sec = -ts.tv_sec - 1;
181 if (ts.tv_sec == 0 && ts.tv_nsec < 0) {
182 ts.tv_nsec = -ts.tv_nsec;
191 if (!atom.loadRelaxed()) {
195 struct sigaction noaction;
196 memset(&noaction, 0,
sizeof(noaction));
197 noaction.sa_handler = SIG_IGN;
198 ::sigaction(SIGPIPE, &noaction,
nullptr);
199 atom.storeRelaxed(1);
203#if defined(Q_PROCESSOR_X86_32) && defined(__GLIBC__)
204# if !__GLIBC_PREREQ(2, 22)
205Q_CORE_EXPORT
int qt_open64(
const char *pathname,
int flags, mode_t);
207# define QT_OPEN qt_open64
223 ::fcntl(
fd, F_SETFD, FD_CLOEXEC);
229#define QT_OPEN qt_safe_open
238#ifdef QT_THREADSAFE_CLOEXEC
241 return ::pipe2(pipefd,
flags);
243 int ret = ::pipe(pipefd);
247 ::fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
248 ::fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
251 if (
flags & O_NONBLOCK) {
252 ::fcntl(pipefd[0], F_SETFL, ::fcntl(pipefd[0], F_GETFL) | O_NONBLOCK);
253 ::fcntl(pipefd[1], F_SETFL, ::fcntl(pipefd[1], F_GETFL) | O_NONBLOCK);
267#ifdef F_DUPFD_CLOEXEC
269 if (
flags & FD_CLOEXEC)
270 cmd = F_DUPFD_CLOEXEC;
271 return ::fcntl(oldfd, cmd, atleast);
274 int ret = ::fcntl(oldfd, F_DUPFD, atleast);
289#ifdef QT_THREADSAFE_CLOEXEC
299 ::fcntl(newfd, F_SETFD,
flags);
311#define QT_READ qt_safe_read
320#define QT_WRITE qt_safe_write
335#define QT_CLOSE qt_safe_close
338#if QT_CONFIG(process)
339static inline int qt_safe_execve(
const char *filename,
char *
const argv[],
347static inline int qt_safe_execv(
const char *
path,
char *
const argv[])
354static inline int qt_safe_execvp(
const char *
file,
char *
const argv[])
361static inline pid_t qt_safe_waitpid(pid_t pid,
int *status,
int options)
369#if !defined(_POSIX_MONOTONIC_CLOCK)
370# define _POSIX_MONOTONIC_CLOCK -1
381# ifdef QT_LINUX_ALWAYS_HAVE_PROCFS
384 static const bool present = (
access(
"/proc/version", F_OK) == 0);
392Q_CORE_EXPORT
int qt_safe_poll(
struct pollfd *
fds, nfds_t nfds,
const struct timespec *timeout_ts);
396 timespec ts, *pts =
nullptr;
400 ts.tv_nsec = (
timeout % 1000) * 1000 * 1000;
409 struct pollfd pfd = {
fd, events, 0 };
EGLint EGLint EGLint EGLint int int int int * fds
Combined button and popup list for selecting options.
#define Q_BASIC_ATOMIC_INITIALIZER(a)
static qint64 qt_safe_write(int fd, const void *data, qint64 len)
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
constexpr bool operator==(const timespec &t1, const timespec &t2)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
Q_CORE_EXPORT int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts)
constexpr bool operator!=(const timespec &t1, const timespec &t2)
static constexpr auto OneSecAsNsecs
timespec qAbsTimespec(timespec ts)
timespec qt_gettime() noexcept
bool qt_haveLinuxProcfs()
constexpr timespec operator+(const timespec &t1, const timespec &t2)
Duration timespecToChrono(timespec ts) noexcept
timeval timespecToTimeval(timespec ts)
static struct pollfd qt_make_pollfd(int fd, short events)
std::chrono::milliseconds timespecToChronoMs(timespec ts) noexcept
constexpr timespec operator*(const timespec &t1, int mul)
static int qt_safe_dup2(int oldfd, int newfd, int flags=FD_CLOEXEC)
timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept
constexpr timespec & normalizedTimespec(timespec &t)
static int qt_poll_msecs(struct pollfd *fds, nfds_t nfds, int timeout)
static int qt_safe_dup(int oldfd, int atleast=0, int flags=FD_CLOEXEC)
#define EINTR_LOOP(var, cmd)
static int qt_safe_close(int fd)
static qint64 qt_safe_write_nosignal(int fd, const void *data, qint64 len)
static int qt_safe_pipe(int pipefd[2], int flags=0)
QByteArray qt_readlink(const char *path)
constexpr timespec & operator+=(timespec &t1, const timespec &t2)
constexpr timespec operator-(const timespec &t1, const timespec &t2)
constexpr bool operator<(const timespec &t1, const timespec &t2)
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * path
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)