41 #ifndef QCORE_UNIX_P_H
42 #define QCORE_UNIX_P_H
55 #include "qplatformdefs.h"
56 #include <QtCore/private/qglobal_p.h>
61 # error "qcore_unix_p.h included on a non-Unix system"
65 #include <sys/types.h>
69 #if !defined (Q_OS_VXWORKS)
70 # if !defined(Q_OS_HPUX) || defined(__ia64)
71 # include <sys/select.h>
73 # include <sys/time.h>
75 # include <selectLib.h>
82 #if !defined(QT_POSIX_IPC) && !defined(QT_NO_SHAREDMEMORY) && !defined(Q_OS_ANDROID)
86 #if defined(Q_OS_VXWORKS)
90 #ifdef QT_NO_NATIVE_POLL
98 #define EINTR_LOOP(var, cmd) \
101 } while (var == -1 && errno == EINTR)
110 while (
t.tv_nsec >= 1000000000) {
112 t.tv_nsec -= 1000000000;
114 while (
t.tv_nsec < 0) {
116 t.tv_nsec += 1000000000;
121 {
return t1.tv_sec <
t2.tv_sec || (
t1.tv_sec ==
t2.tv_sec &&
t1.tv_nsec <
t2.tv_nsec); }
123 {
return t1.tv_sec ==
t2.tv_sec &&
t1.tv_nsec ==
t2.tv_nsec; }
125 {
return !(
t1 ==
t2); }
128 t1.tv_sec +=
t2.tv_sec;
129 t1.tv_nsec +=
t2.tv_nsec;
135 tmp.tv_sec =
t1.tv_sec +
t2.tv_sec;
136 tmp.tv_nsec =
t1.tv_nsec +
t2.tv_nsec;
142 tmp.tv_sec =
t1.tv_sec - (
t2.tv_sec - 1);
143 tmp.tv_nsec =
t1.tv_nsec - (
t2.tv_nsec + 1000000000);
149 tmp.tv_sec =
t1.tv_sec * mul;
150 tmp.tv_nsec =
t1.tv_nsec * mul;
156 tv.tv_sec = ts.tv_sec;
157 tv.tv_usec = ts.tv_nsec / 1000;
170 struct sigaction noaction;
171 memset(&noaction, 0,
sizeof(noaction));
172 noaction.sa_handler = SIG_IGN;
173 ::sigaction(SIGPIPE, &noaction,
nullptr);
178 #if defined(Q_PROCESSOR_X86_32) && defined(__GLIBC__)
179 # if !__GLIBC_PREREQ(2, 22)
180 Q_CORE_EXPORT
int qt_open64(
const char *pathname,
int flags,
mode_t);
182 # define QT_OPEN qt_open64
188 static inline int qt_safe_open(
const char *pathname,
int flags,
mode_t mode = 0777)
198 ::fcntl(
fd, F_SETFD, FD_CLOEXEC);
204 #define QT_OPEN qt_safe_open
209 static inline int qt_safe_pipe(
int pipefd[2],
int flags = 0)
213 #ifdef QT_THREADSAFE_CLOEXEC
216 return ::pipe2(pipefd,
flags);
218 int ret = ::pipe(pipefd);
222 ::fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
223 ::fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
226 if (
flags & O_NONBLOCK) {
227 ::fcntl(pipefd[0], F_SETFL, ::fcntl(pipefd[0], F_GETFL) | O_NONBLOCK);
228 ::fcntl(pipefd[1], F_SETFL, ::fcntl(pipefd[1], F_GETFL) | O_NONBLOCK);
238 static inline int qt_safe_dup(
int oldfd,
int atleast = 0,
int flags = FD_CLOEXEC)
242 #ifdef F_DUPFD_CLOEXEC
244 if (
flags & FD_CLOEXEC)
245 cmd = F_DUPFD_CLOEXEC;
246 return ::fcntl(oldfd, cmd, atleast);
249 int ret = ::fcntl(oldfd, F_DUPFD, atleast);
259 static inline int qt_safe_dup2(
int oldfd,
int newfd,
int flags = FD_CLOEXEC)
264 #ifdef QT_THREADSAFE_CLOEXEC
274 ::fcntl(newfd, F_SETFD,
flags);
286 #define QT_READ qt_safe_read
295 #define QT_WRITE qt_safe_write
303 static inline int qt_safe_close(
int fd)
310 #define QT_CLOSE qt_safe_close
313 #if QT_CONFIG(process)
314 static inline int qt_safe_execve(
const char *
filename,
char *
const argv[],
322 static inline int qt_safe_execv(
const char *
path,
char *
const argv[])
329 static inline int qt_safe_execvp(
const char *
file,
char *
const argv[])
336 static inline pid_t qt_safe_waitpid(pid_t pid,
int *status,
int options)
344 #if !defined(_POSIX_MONOTONIC_CLOCK)
345 # define _POSIX_MONOTONIC_CLOCK -1
357 # ifdef QT_LINUX_ALWAYS_HAVE_PROCFS
360 static const bool present = (
access(
"/proc/version",
F_OK) == 0);
368 Q_CORE_EXPORT
int qt_safe_poll(
struct pollfd *fds, nfds_t nfds,
const struct timespec *timeout_ts);
370 static inline int qt_poll_msecs(
struct pollfd *fds, nfds_t nfds,
int timeout)
372 timespec ts, *pts =
nullptr;
376 ts.tv_nsec = (
timeout % 1000) * 1000 * 1000;
383 static inline struct pollfd qt_make_pollfd(int
fd, short events)
385 struct pollfd pfd = {
fd, events, 0 };
void storeRelaxed(T newValue) noexcept
T loadRelaxed() const noexcept
The QByteArray class provides an array of bytes.
const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
bool operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
template< typename Enum > bool operator!=(Enum lhs, QFlags< Enum > rhs)
template< typename Enum > bool operator==(Enum lhs, QFlags< Enum > rhs)
QMargins operator*(const QMargins &margins, int factor)
QMargins operator-(const QMargins &m1, const QMargins &m2)
auto it unsigned count const
#define Q_BASIC_ATOMIC_INITIALIZER(a)
constexpr timespec & operator+=(timespec &t1, const timespec &t2)
Q_CORE_EXPORT int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts)
QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(pollfd, Q_PRIMITIVE_TYPE)
timeval timespecToTimeval(const timespec &ts)
timespec qt_gettime() noexcept
constexpr timespec & normalizedTimespec(timespec &t)
bool qt_haveLinuxProcfs()
void qt_nanosleep(timespec amount)
#define EINTR_LOOP(var, cmd)
QByteArray qt_readlink(const char *path)
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