summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Zander <t.zander@nokia.com>2010-09-23 14:10:46 (GMT)
committerThomas Zander <t.zander@nokia.com>2010-09-23 15:32:47 (GMT)
commit2645784f05db7b1e631621c511e94c88fc5cd211 (patch)
tree7fb8c25792da90509fc020ddb49b9f227dcaf2c8
parent59491b5cb9c7dc54f701ba19185fede58a7355db (diff)
downloadQt-2645784f05db7b1e631621c511e94c88fc5cd211.zip
Qt-2645784f05db7b1e631621c511e94c88fc5cd211.tar.gz
Qt-2645784f05db7b1e631621c511e94c88fc5cd211.tar.bz2
Move resolving names to qfilesystemengine
Resolve username and group names code is now in the QFileSystemEngine Reviewed-by: João Abecasis
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp53
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp47
2 files changed, 54 insertions, 46 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index c17d4c7..1dee09b 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -45,6 +45,8 @@
#include "qfsfileengine.h"
#include "qfile.h"
+#include <QtCore/qvarlengtharray.h>
+
#include <stdlib.h> // for realpath()
#include <unistd.h>
#include <stdio.h>
@@ -275,13 +277,60 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry)
//static
QString QFileSystemEngine::resolveUserName(uint userId)
{
- return QString(); // TODO
+#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
+ int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (size_max == -1)
+ size_max = 1024;
+ QVarLengthArray<char, 1024> buf(size_max);
+#endif
+
+ struct passwd *pw = 0;
+#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
+ struct passwd entry;
+ getpwuid_r(userId, &entry, buf.data(), buf.size(), &pw);
+#else
+ pw = getpwuid(userId);
+#endif
+ if (pw)
+ return QFile::decodeName(QByteArray(pw->pw_name));
+ return QString();
}
//static
QString QFileSystemEngine::resolveGroupName(uint groupId)
{
- return QString(); // TODO
+#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
+ int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (size_max == -1)
+ size_max = 1024;
+ QVarLengthArray<char, 1024> buf(size_max);
+#endif
+
+#if !defined(Q_OS_SYMBIAN)
+ struct group *gr = 0;
+#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
+ size_max = sysconf(_SC_GETGR_R_SIZE_MAX);
+ if (size_max == -1)
+ size_max = 1024;
+ buf.resize(size_max);
+ struct group entry;
+ // Some large systems have more members than the POSIX max size
+ // Loop over by doubling the buffer size (upper limit 250k)
+ for (unsigned size = size_max; size < 256000; size += size)
+ {
+ buf.resize(size);
+ // ERANGE indicates that the buffer was too small
+ if (!getgrgid_r(groupId, &entry, buf.data(), buf.size(), &gr)
+ || errno != ERANGE)
+ break;
+ }
+#else
+ gr = getgrgid(groupId);
+#endif
+ if (gr)
+ return QFile::decodeName(QByteArray(gr->gr_name));
+#endif
+ return QString();
}
//static
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index 7b7cd7f..0845cb3 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -892,50 +892,9 @@ uint QFSFileEngine::ownerId(FileOwner own) const
QString QFSFileEngine::owner(FileOwner own) const
{
-#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
- int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
- if (size_max == -1)
- size_max = 1024;
- QVarLengthArray<char, 1024> buf(size_max);
-#endif
-
- if (own == OwnerUser) {
- struct passwd *pw = 0;
-#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
- struct passwd entry;
- getpwuid_r(ownerId(own), &entry, buf.data(), buf.size(), &pw);
-#else
- pw = getpwuid(ownerId(own));
-#endif
- if (pw)
- return QFile::decodeName(QByteArray(pw->pw_name));
- } else if (own == OwnerGroup) {
-#if !defined(Q_OS_SYMBIAN)
- struct group *gr = 0;
-#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
- size_max = sysconf(_SC_GETGR_R_SIZE_MAX);
- if (size_max == -1)
- size_max = 1024;
- buf.resize(size_max);
- struct group entry;
- // Some large systems have more members than the POSIX max size
- // Loop over by doubling the buffer size (upper limit 250k)
- for (unsigned size = size_max; size < 256000; size += size)
- {
- buf.resize(size);
- // ERANGE indicates that the buffer was too small
- if (!getgrgid_r(ownerId(own), &entry, buf.data(), buf.size(), &gr)
- || errno != ERANGE)
- break;
- }
-#else
- gr = getgrgid(ownerId(own));
-#endif
- if (gr)
- return QFile::decodeName(QByteArray(gr->gr_name));
-#endif
- }
- return QString();
+ if (own == OwnerUser)
+ return QFileSystemEngine::resolveUserName(ownerId(own));
+ return QFileSystemEngine::resolveGroupName(ownerId(own));
}
bool QFSFileEngine::setPermissions(uint perms)