summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemengine_unix.cpp
diff options
context:
space:
mode:
authorThomas Zander <t.zander@nokia.com>2010-09-23 16:10:46 +0200
committerThomas Zander <t.zander@nokia.com>2010-09-23 17:32:47 +0200
commit2645784f05db7b1e631621c511e94c88fc5cd211 (patch)
tree7fb8c25792da90509fc020ddb49b9f227dcaf2c8 /src/corelib/io/qfilesystemengine_unix.cpp
parent59491b5cb9c7dc54f701ba19185fede58a7355db (diff)
Move resolving names to qfilesystemengine
Resolve username and group names code is now in the QFileSystemEngine Reviewed-by: João Abecasis
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index c17d4c72a4..1dee09b2ee 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