[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/frameworks] /: Port bunch of direct POSIX calls to qplatformdefs calls
From:       Martin Klapetek <mklapetek () kde ! org>
Date:       2013-09-03 9:44:15
Message-ID: E1VGn9j-0004xy-GX () scm ! kde ! org
[Download RAW message or body]

Git commit 588d427520db48457a53cd5bc1d1c4d5209ccc3a by Martin Klapetek.
Committed on 03/09/2013 at 09:43.
Pushed by mklapetek into branch 'frameworks'.

Port bunch of direct POSIX calls to qplatformdefs calls

REVIEW: 112229

M  +3    -3    kdesu/client.cpp
M  +2    -1    kdesu/su.cpp
M  +1    -1    kioslave/file/file_unix.cpp
M  +3    -3    kioslave/ftp/ftp.cpp
M  +5    -4    staging/kio/src/widgets/kdirmodel.cpp
M  +5    -6    tier1/kconfig/src/core/kconfigini.cpp
M  +1    -1    tier1/kcoreaddons/src/lib/io/kdirwatch.cpp
M  +2    -1    tier1/kcoreaddons/src/lib/io/kprocess.cpp

http://commits.kde.org/kdelibs/588d427520db48457a53cd5bc1d1c4d5209ccc3a

diff --git a/kdesu/client.cpp b/kdesu/client.cpp
index 065bb0a..8a3230a 100644
--- a/kdesu/client.cpp
+++ b/kdesu/client.cpp
@@ -48,7 +48,7 @@ public:
 };
 
 #ifndef SUN_LEN
-#define SUN_LEN(ptr) ((socklen_t) (((struct sockaddr_un *) 0)->sun_path) \
+#define SUN_LEN(ptr) ((QT_SOCKLEN_T) (((struct sockaddr_un *) 0)->sun_path) \
                      + strlen ((ptr)->sun_path))
 #endif
 
@@ -101,7 +101,7 @@ int KDEsuClient::connect()
     addr.sun_family = AF_UNIX;
     strcpy(addr.sun_path, d->sock.constData());
 
-    if (::connect(d->sockfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) < 0)
+    if (QT_SOCKET_CONNECT(d->sockfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) < 0)
     {
         qWarning() << "[" << __FILE__ << ":" << __LINE__ << "] " << "connect():" << strerror(errno);
         close(d->sockfd); d->sockfd = -1;
@@ -152,7 +152,7 @@ int KDEsuClient::connect()
 # endif
 #else
     struct ucred cred;
-    socklen_t siz = sizeof(cred);
+    QT_SOCKLEN_T siz = sizeof(cred);
 
     // Security: if socket exists, we must own it
     if (getsockopt(d->sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &siz) == 0)
diff --git a/kdesu/su.cpp b/kdesu/su.cpp
index 01a992c..8cd5b25 100644
--- a/kdesu/su.cpp
+++ b/kdesu/su.cpp
@@ -36,6 +36,7 @@
 #include <ksharedconfig.h>
 #include <klocalizedstring.h>
 #include <qstandardpaths.h>
+#include <qplatformdefs.h>
 #include <kuser.h>
 
 #ifndef __PATH_SU
@@ -146,7 +147,7 @@ int SuProcess::exec(const char *password, int check)
         command = __PATH_SU;
     }
 
-    if (::access(command.constData(), X_OK) != 0)
+    if (QT_ACCESS(command.constData(), X_OK) != 0)
     {
         command = QFile::encodeName(QStandardPaths::findExecutable(d->m_superUserCommand.toLatin1()));
         if (command.isEmpty())
diff --git a/kioslave/file/file_unix.cpp b/kioslave/file/file_unix.cpp
index aaf7172..48bd0ba 100644
--- a/kioslave/file/file_unix.cpp
+++ b/kioslave/file/file_unix.cpp
@@ -542,7 +542,7 @@ void FileProtocol::del(const QUrl& url, bool isfile)
           if (!deleteRecursive(path))
               return;
       }
-      if ( ::rmdir( _path.data() ) == -1 ) {
+      if (QT_RMDIR(_path.data()) == -1 ) {
 	if ((errno == EACCES) || (errno == EPERM))
 	  error(KIO::ERR_ACCESS_DENIED, path);
 	else {
diff --git a/kioslave/ftp/ftp.cpp b/kioslave/ftp/ftp.cpp
index 31e24db..37e682e 100644
--- a/kioslave/ftp/ftp.cpp
+++ b/kioslave/ftp/ftp.cpp
@@ -2183,7 +2183,7 @@ Ftp::StatusCode Ftp::ftpPut(int& iError, int iCopyFile, const QUrl& dest_url,
       if(processed_size-offset > 1024 * 64)
         iBlockSize = maximumIpcSize;
       buffer.resize(iBlockSize);
-      result = ::read(iCopyFile, buffer.data(), buffer.size());
+      result = QT_READ(iCopyFile, buffer.data(), buffer.size());
       if(result < 0)
         iError = ERR_COULD_NOT_WRITE;
       else
@@ -2375,7 +2375,7 @@ void Ftp::copy( const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlag
 
   // perform clean-ups and report error (if any)
   if(iCopyFile != -1)
-    ::close(iCopyFile);
+      QT_CLOSE(iCopyFile);
   ftpCloseCommand();                        // must close command!
   if(iError)
     error(iError, sCopyFile);
@@ -2498,7 +2498,7 @@ Ftp::StatusCode Ftp::ftpCopyGet(int& iError, int& iCopyFile, const QString &sCop
 
   // delegate the real work (iError gets status) ...
   StatusCode iRes = ftpGet(iError, iCopyFile, url, hCopyOffset);
-  if( ::close(iCopyFile) && iRes == statusSuccess )
+  if (QT_CLOSE(iCopyFile) && iRes == statusSuccess)
   {
     iError = ERR_COULD_NOT_WRITE;
     iRes = statusClientError;
diff --git a/staging/kio/src/widgets/kdirmodel.cpp b/staging/kio/src/widgets/kdirmodel.cpp
index 77b978a..ea290d0 100644
--- a/staging/kio/src/widgets/kdirmodel.cpp
+++ b/staging/kio/src/widgets/kdirmodel.cpp
@@ -34,6 +34,7 @@
 #include <QDir>
 #include <QIcon>
 #include <QLocale>
+#include <qplatformdefs.h>
 #include <sys/types.h>
 #include <dirent.h>
 
@@ -738,11 +739,11 @@ QVariant KDirModel::data( const QModelIndex & index, int role ) const
                             FindClose( hFile );
                         }
 #else
-                        DIR* dir = ::opendir(QFile::encodeName(path));
+                        DIR* dir = QT_OPENDIR(QFile::encodeName(path));
                         if (dir) {
                             count = 0;
-                            struct dirent *dirEntry = 0;
-                            while ((dirEntry = ::readdir(dir))) {
+                            QT_DIRENT *dirEntry = 0;
+                            while ((dirEntry = QT_READDIR(dir))) {
                                 if (dirEntry->d_name[0] == '.') {
                                     if (dirEntry->d_name[1] == '\0') // skip "."
                                         continue;
@@ -751,7 +752,7 @@ QVariant KDirModel::data( const QModelIndex & index, int role ) const
                                 }
                                 ++count;
                             }
-                            ::closedir(dir);
+                            QT_CLOSEDIR(dir);
                         }
 #endif
                         //qDebug() << "child count for " << path << ":" << count;
diff --git a/tier1/kconfig/src/core/kconfigini.cpp b/tier1/kconfig/src/core/kconfigini.cpp
index c484ecb..e44d01f 100644
--- a/tier1/kconfig/src/core/kconfigini.cpp
+++ b/tier1/kconfig/src/core/kconfigini.cpp
@@ -34,6 +34,7 @@
 #include <qfile.h>
 #include <qfileinfo.h>
 #include <qdebug.h>
+#include <qplatformdefs.h>
 
 #include <unistd.h> // getuid, close
 #include <sys/types.h> // uid_t
@@ -464,13 +465,13 @@ bool KConfigIniBackend::writeConfig(const QByteArray& locale, KEntryMap& entryMa
     } else {
         // Open existing file. *DON'T* create it if it suddenly does not exist!
 #ifdef Q_OS_UNIX
-        int fd = ::open(QFile::encodeName(filePath()).constData(), O_WRONLY | O_TRUNC);
+        int fd = QT_OPEN(QFile::encodeName(filePath()).constData(), O_WRONLY | O_TRUNC);
         if (fd < 0) {
             return false;
         }
         FILE *fp = ::fdopen(fd, "w");
         if (!fp) {
-            ::close(fd);
+            QT_CLOSE(fd);
             return false;
         }
         QFile f;
@@ -499,10 +500,6 @@ bool KConfigIniBackend::isWritable() const
 {
     const QString filePath = this->filePath();
     if (!filePath.isEmpty()) {
-        // Qt 5 TODO: QFileInfo::canBeCreated or something.
-        if (::access(QFile::encodeName(filePath).constData(), W_OK) == 0) {
-            return true;
-        }
         QFileInfo file(filePath);
         if (!file.exists()) {
             // If the file does not exist, check if the deepest
@@ -517,6 +514,8 @@ bool KConfigIniBackend::isWritable() const
                 dir.setFile(parent);
             }
             return dir.isDir() && dir.isWritable();
+        } else {
+            return file.isWritable();
         }
     }
 
diff --git a/tier1/kcoreaddons/src/lib/io/kdirwatch.cpp b/tier1/kcoreaddons/src/lib/io/kdirwatch.cpp
index a95139e..a56801a 100644
--- a/tier1/kcoreaddons/src/lib/io/kdirwatch.cpp
+++ b/tier1/kcoreaddons/src/lib/io/kdirwatch.cpp
@@ -264,7 +264,7 @@ KDirWatchPrivate::~KDirWatchPrivate()
 #endif
 #if HAVE_SYS_INOTIFY_H
   if ( supports_inotify )
-    ::close( m_inotify_fd );
+      QT_CLOSE(m_inotify_fd);
 #endif
 #if HAVE_QFILESYSTEMWATCHER
   delete fsWatcher;
diff --git a/tier1/kcoreaddons/src/lib/io/kprocess.cpp b/tier1/kcoreaddons/src/lib/io/kprocess.cpp
index 8f9c1af..6dfd11c 100644
--- a/tier1/kcoreaddons/src/lib/io/kprocess.cpp
+++ b/tier1/kcoreaddons/src/lib/io/kprocess.cpp
@@ -22,6 +22,7 @@
 #include "kprocess_p.h"
 
 #include <qstandardpaths.h>
+#include <qplatformdefs.h>
 #include <kshell.h>
 #ifdef Q_OS_WIN
 # include <kshell_p.h>
@@ -60,7 +61,7 @@ void KProcessPrivate::writeAll(const QByteArray &buf, int fd)
 #else
     int off = 0;
     do {
-        int ret = ::write(fd, buf.data() + off, buf.size() - off);
+        int ret = QT_WRITE(fd, buf.data() + off, buf.size() - off);
         if (ret < 0) {
             if (errno != EINTR)
                 return;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic