42 #ifndef QCORE_UNIX_P_H 43 #define QCORE_UNIX_P_H 56 #include "qplatformdefs.h" 60 # error "qcore_unix_p.h included on a non-Unix system" 64 #include <sys/types.h> 72 #if defined(Q_OS_VXWORKS) 78 #if defined(Q_OS_LINUX) && defined(O_CLOEXEC) 79 # define QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC 1 81 namespace QtLibcSupplement {
83 {
errno = ENOSYS;
return -1; }
84 inline int dup3(
int,
int,
int)
85 {
errno = ENOSYS;
return -1; }
86 inline int pipe2(
int [],
int )
87 {
errno = ENOSYS;
return -1; }
93 # define QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC 0 96 #define EINTR_LOOP(var, cmd) \ 99 } while (var == -1 && errno == EINTR) 106 while (t.tv_usec > 1000000
l) {
108 t.tv_usec -= 1000000
l;
110 while (t.tv_usec < 0
l) {
112 t.tv_usec += 1000000
l;
116 inline bool operator<(
const timeval &t1,
const timeval &t2)
117 {
return t1.tv_sec < t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec); }
119 {
return t1.tv_sec == t2.tv_sec && t1.tv_usec == t2.tv_usec; }
122 t1.tv_sec += t2.tv_sec;
123 t1.tv_usec += t2.tv_usec;
126 inline timeval
operator+(
const timeval &t1,
const timeval &t2)
129 tmp.tv_sec = t1.tv_sec + t2.tv_sec;
130 tmp.tv_usec = t1.tv_usec + t2.tv_usec;
133 inline timeval
operator-(
const timeval &t1,
const timeval &t2)
136 tmp.tv_sec = t1.tv_sec - (t2.tv_sec - 1);
137 tmp.tv_usec = t1.tv_usec - (t2.tv_usec + 1000000);
143 tmp.tv_sec = t1.tv_sec * mul;
144 tmp.tv_usec = t1.tv_usec * mul;
150 #ifndef Q_NO_POSIX_SIGNALS 158 memset(&noaction, 0,
sizeof(noaction));
159 noaction.sa_handler = SIG_IGN;
182 ::fcntl(fd, F_SETFD, FD_CLOEXEC);
186 #define QT_OPEN qt_safe_open 188 #ifndef Q_OS_VXWORKS // no POSIX pipes in VxWorks 194 Q_ASSERT((flags & ~(O_CLOEXEC | O_NONBLOCK)) == 0);
196 Q_ASSERT((flags & ~O_NONBLOCK) == 0);
200 #if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(O_CLOEXEC) 203 ret = ::pipe2(pipefd, flags);
204 if (ret == 0 ||
errno != ENOSYS)
208 ret = ::pipe(pipefd);
212 ::fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
213 ::fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
216 if (flags & O_NONBLOCK) {
217 ::fcntl(pipefd[0], F_SETFL, ::
fcntl(pipefd[0], F_GETFL) | O_NONBLOCK);
218 ::fcntl(pipefd[1], F_SETFL, ::
fcntl(pipefd[1], F_GETFL) | O_NONBLOCK);
224 #endif // Q_OS_VXWORKS 227 static inline int qt_safe_dup(
int oldfd,
int atleast = 0,
int flags = FD_CLOEXEC)
229 Q_ASSERT(flags == FD_CLOEXEC || flags == 0);
232 #ifdef F_DUPFD_CLOEXEC 234 if (flags & FD_CLOEXEC) {
235 ret =
::fcntl(oldfd, F_DUPFD_CLOEXEC, atleast);
236 if (ret != -1 ||
errno != EINVAL)
242 ret =
::fcntl(oldfd, F_DUPFD, atleast);
244 if (flags && ret != -1)
251 static inline int qt_safe_dup2(
int oldfd,
int newfd,
int flags = FD_CLOEXEC)
253 Q_ASSERT(flags == FD_CLOEXEC || flags == 0);
256 #if QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC && defined(O_CLOEXEC) 258 if (flags & FD_CLOEXEC) {
259 EINTR_LOOP(ret, ::dup3(oldfd, newfd, O_CLOEXEC));
260 if (ret == 0 ||
errno != ENOSYS)
269 ::fcntl(newfd, F_SETFD, flags);
280 #define QT_READ qt_safe_read 289 #define QT_WRITE qt_safe_write 304 #define QT_CLOSE qt_safe_close 308 #if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_VXWORKS) 313 EINTR_LOOP(ret, ::execve(filename, argv, envp));
332 #ifndef Q_OS_VXWORKS // no processes on VxWorks 336 EINTR_LOOP(ret, ::waitpid(pid, status, options));
340 #endif // Q_OS_VXWORKS 342 #if !defined(_POSIX_MONOTONIC_CLOCK) 343 # define _POSIX_MONOTONIC_CLOCK -1 349 const struct timeval *tv);
timeval operator-(const timeval &t1, const timeval &t2)
#define QT_END_NAMESPACE
This macro expands to.
#define EINTR_LOOP(var, cmd)
static int qt_safe_execvp(const char *file, char *const argv[])
static LibLoadStatus status
static int qt_safe_close(int fd)
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timeval *tv)
static int qt_safe_execve(const char *filename, char *const argv[], char *const envp[])
#define QT_BEGIN_NAMESPACE
This macro expands to.
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
timeval & normalizedTimeval(timeval &t)
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
static int qt_safe_dup2(int oldfd, int newfd, int flags=FD_CLOEXEC)
static const char * data(const QByteArray &arr)
static int qt_safe_pipe(int pipefd[2], int flags=0)
timeval operator*(const timeval &t1, int mul)
static int qt_safe_execv(const char *path, char *const argv[])
bool operator==(const timeval &t1, const timeval &t2)
bool operator<(const timeval &t1, const timeval &t2)
int sigaction(int, const struct sigaction *, struct sigaction *)
timeval & operator+=(timeval &t1, const timeval &t2)
static qint64 qt_safe_write_nosignal(int fd, const void *data, qint64 len)
static pid_t qt_safe_waitpid(pid_t pid, int *status, int options)
static qint64 qt_safe_write(int fd, const void *data, qint64 len)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
static int qt_safe_dup(int oldfd, int atleast=0, int flags=FD_CLOEXEC)
timeval operator+(const timeval &t1, const timeval &t2)