return false;
}
- const int sourcefd = QT_OPEN(spath.constData(), O_RDONLY);
+ const int sourcefd = qt_safe_open(spath.constData(), O_RDONLY);
if (sourcefd == -1) {
*error = errno;
return false;
}
- const int targetfd = QT_CREAT(tpath.constData(), st.st_mode);
+ const int targetfd = qt_safe_creat(tpath.constData(), st.st_mode);
if (targetfd == -1) {
*error = errno;
- ::close(sourcefd);
+ qt_safe_close(sourcefd);
return false;
}
while (sendresult != tocopy) {
if (sendresult == -1) {
*error = errno;
- ::close(sourcefd);
- ::close(targetfd);
+ qt_safe_close(sourcefd);
+ qt_safe_close(targetfd);
return false;
}
tocopy -= sendresult;
int sendresult = ::sendfile(sourcefd, targetfd, QT_OFF_T(0), size_t(0), Q_NULLPTR, &totalwrite, SF_SYNC);
if (QT_OFF_T(sendresult) != totalwrite) {
*error = errno;
- ::close(sourcefd);
- ::close(targetfd);
+ qt_safe_close(sourcefd);
+ qt_safe_close(targetfd);
return false;
}
#else
size_t totalwrite = 0;
char copybuffer[QT_BUFFSIZE];
while (QT_OFF_T(totalwrite) != tocopy) {
- const size_t readresult = QT_READ(sourcefd, copybuffer, sizeof(copybuffer));
+ const size_t readresult = qt_safe_read(sourcefd, copybuffer, sizeof(copybuffer));
if (readresult == -1) {
*error = errno;
- ::close(sourcefd);
- ::close(targetfd);
+ qt_safe_close(sourcefd);
+ qt_safe_close(targetfd);
return false;
}
- const size_t writeresult = QT_WRITE(targetfd, copybuffer, readresult);
+ const size_t writeresult = qt_safe_write(targetfd, copybuffer, readresult);
if (writeresult != readresult) {
*error = errno;
- ::close(sourcefd);
- ::close(targetfd);
+ qt_safe_close(sourcefd);
+ qt_safe_close(targetfd);
return false;
}
}
#endif
- ::close(sourcefd);
- ::close(targetfd);
+ qt_safe_close(sourcefd);
+ qt_safe_close(targetfd);
return true;
}
}
}
-// don't call QT_OPEN or ::open
-// call qt_safe_open
+// don't call QT_OPEN or ::open, call qt_safe_open
static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 0777)
{
#ifdef O_CLOEXEC
#endif
return fd;
}
-#undef QT_OPEN
-#define QT_OPEN qt_safe_open
-// don't call ::pipe
-// call qt_safe_pipe
+// don't call ::pipe or ::pipe2, call qt_safe_pipe
static inline int qt_safe_pipe(int pipefd[2], int flags = 0)
{
#ifdef O_CLOEXEC
#endif
}
-// don't call dup or fcntl(F_DUPFD)
+// don't call dup or fcntl(F_DUPFD), call qt_safe_dup
static inline int qt_safe_dup(int oldfd)
{
#ifdef F_DUPFD_CLOEXEC
#endif
}
-// don't call dup2
-// call qt_safe_dup2
+// don't call dup2, call qt_safe_dup2
static inline int qt_safe_dup2(int oldfd, int newfd)
{
int ret;
return ret;
}
+// don't call QT_READ or ::read, call qt_safe_read
static inline qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
{
qint64 ret = 0;
EINTR_LOOP(ret, QT_READ(fd, data, maxlen));
return ret;
}
-#undef QT_READ
-#define QT_READ qt_safe_read
+// don't call QT_WRITE or ::write, call qt_safe_write
static inline qint64 qt_safe_write(int fd, const void *data, qint64 len)
{
qint64 ret = 0;
EINTR_LOOP(ret, QT_WRITE(fd, data, len));
return ret;
}
-#undef QT_WRITE
-#define QT_WRITE qt_safe_write
static inline qint64 qt_safe_write_nosignal(int fd, const void *data, qint64 len)
{
return qt_safe_write(fd, data, len);
}
+// don't call QT_CREAT or ::creat, call qt_safe_creat
+static inline int qt_safe_creat(const char* path, mode_t flags)
+{
+ int ret;
+ EINTR_LOOP(ret, QT_CREAT(path, flags));
+ return ret;
+}
+
+// don't call QT_CLOSE or ::close, call qt_safe_close
static inline int qt_safe_close(int fd)
{
int ret;
EINTR_LOOP(ret, QT_CLOSE(fd));
return ret;
}
-#undef QT_CLOSE
-#define QT_CLOSE qt_safe_close
+// don't call ::execve, call qt_safe_execve
static inline int qt_safe_execve(const char *filename, char *const argv[],
char *const envp[])
{
return ret;
}
+// don't call ::execv, call qt_safe_execv
static inline int qt_safe_execv(const char *path, char *const argv[])
{
int ret;
return ret;
}
+// don't call ::execvp, call qt_safe_execvp
static inline int qt_safe_execvp(const char *file, char *const argv[])
{
int ret;
return ret;
}
+// don't call ::waitpid, call qt_safe_waitpid
static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options)
{
int ret;
timeval qt_gettime(); // in qelapsedtimer_unix.cpp
+// don't call ::select, call qt_safe_select
Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
const struct timeval *tv);