OSDN Git Service

do not redefine QT_OPEN, QT_READ, QT_WRITE and QT_CLOSE from qcore_unix_p header
authorIvailo Monev <xakepa10@gmail.com>
Sun, 14 Feb 2021 17:35:22 +0000 (19:35 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 14 Feb 2021 17:35:22 +0000 (19:35 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/io/qfilesystemengine_unix.cpp
src/core/io/qtemporaryfile.cpp
src/core/kernel/qcore_unix_p.h
src/gui/painting/qpdf.cpp
src/network/socket/qlocalserver_unix.cpp

index 6f899a6..67ead5e 100644 (file)
@@ -313,16 +313,16 @@ bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSyst
             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;
     }
 
@@ -338,8 +338,8 @@ bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSyst
     while (sendresult != tocopy) {
         if (sendresult == -1) {
             *error = errno;
-            ::close(sourcefd);
-            ::close(targetfd);
+            qt_safe_close(sourcefd);
+            qt_safe_close(targetfd);
             return false;
         }
         tocopy -= sendresult;
@@ -355,27 +355,27 @@ bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSyst
     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;
         }
 
@@ -383,8 +383,8 @@ bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSyst
     }
 #endif
 
-    ::close(sourcefd);
-    ::close(targetfd);
+    qt_safe_close(sourcefd);
+    qt_safe_close(targetfd);
     return true;
 }
 
index c76becd..fc5c555 100644 (file)
@@ -27,7 +27,7 @@
 #include "qfile_p.h"
 #include "qfsfileengine_p.h"
 #include "qfilesystemengine_p.h"
-#include "qcore_unix_p.h"       // overrides QT_OPEN
+#include "qcore_unix_p.h"
 
 #include <errno.h>
 
@@ -144,7 +144,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
     }
 
     // Create file and obtain handle
-    d->fd = QT_OPEN(data, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR, 0600);
+    d->fd = qt_safe_open(data, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR, 0600);
 
     if (d->fd == -1) {
         setError(QFile::OpenError, qt_error_string(errno));
index 9c04df2..8a43700 100644 (file)
@@ -108,8 +108,7 @@ static inline void qt_ignore_sigpipe()
     }
 }
 
-// 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
@@ -126,11 +125,8 @@ static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 07
 #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
@@ -160,7 +156,7 @@ static inline int qt_safe_pipe(int pipefd[2], int flags = 0)
 #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
@@ -174,8 +170,7 @@ static inline int qt_safe_dup(int oldfd)
 #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;
@@ -183,23 +178,21 @@ static inline int qt_safe_dup2(int oldfd, int newfd)
     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)
 {
@@ -207,15 +200,23 @@ 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[])
 {
@@ -224,6 +225,7 @@ static inline int qt_safe_execve(const char *filename, char *const argv[],
     return ret;
 }
 
+// don't call ::execv, call qt_safe_execv
 static inline int qt_safe_execv(const char *path, char *const argv[])
 {
     int ret;
@@ -231,6 +233,7 @@ static inline int qt_safe_execv(const char *path, char *const argv[])
     return ret;
 }
 
+// don't call ::execvp, call qt_safe_execvp
 static inline int qt_safe_execvp(const char *file, char *const argv[])
 {
     int ret;
@@ -238,6 +241,7 @@ static inline int qt_safe_execvp(const char *file, char *const argv[])
     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;
@@ -247,6 +251,7 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options)
 
 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);
 
index 47fda34..62c27ca 100644 (file)
@@ -27,7 +27,6 @@
 #include "qprinterinfo.h"
 #include "qnumeric.h"
 #include "qx11info_x11.h"
-#include "qcore_unix_p.h" // overrides QT_OPEN
 
 QT_BEGIN_NAMESPACE
 
@@ -1928,7 +1927,3 @@ QRect QPdfBaseEnginePrivate::pageRect() const
 #endif
 
 QT_END_NAMESPACE
-
-
-
-
index 0b0314f..225d9b8 100644 (file)
@@ -88,7 +88,7 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
         setError(QLatin1String("QLocalServer::listen"));
         // if address is in use already, just close the socket, but do not delete the file
         if(errno == EADDRINUSE)
-            QT_CLOSE(listenSocket);
+            qt_safe_close(listenSocket);
         // otherwise, close the socket and delete the file
         else
             closeServer();
@@ -128,7 +128,7 @@ void QLocalServerPrivate::closeServer()
     }
 
     if (-1 != listenSocket)
-        QT_CLOSE(listenSocket);
+        qt_safe_close(listenSocket);
     listenSocket = -1;
 
     if (!fullServerName.isEmpty())