summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qlockfile_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qlockfile_unix.cpp')
-rw-r--r--src/corelib/io/qlockfile_unix.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp
index d6ea2f1f2d..815c0f025b 100644
--- a/src/corelib/io/qlockfile_unix.cpp
+++ b/src/corelib/io/qlockfile_unix.cpp
@@ -56,6 +56,7 @@
# include <cstdio>
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
# include <sys/user.h>
+# include <libutil.h>
#endif
QT_BEGIN_NAMESPACE
@@ -218,24 +219,25 @@ QString QLockFilePrivate::processNameByPid(qint64 pid)
#if defined(Q_OS_OSX)
char name[1024];
proc_name(pid, name, sizeof(name) / sizeof(char));
- return QString::fromUtf8(name);
+ return QFile::decodeName(name);
#elif defined(Q_OS_LINUX)
if (!QFile::exists(QStringLiteral("/proc/version")))
return QString();
char exePath[64];
- char buf[PATH_MAX];
- memset(buf, 0, sizeof(buf));
+ char buf[PATH_MAX + 1];
sprintf(exePath, "/proc/%lld/exe", pid);
- if (readlink(exePath, buf, sizeof(buf)) < 0) {
+ size_t len = (size_t)readlink(exePath, buf, sizeof(buf));
+ if (len >= sizeof(buf)) {
// The pid is gone. Return some invalid process name to fail the test.
return QStringLiteral("/ERROR/");
}
- return QFileInfo(QString::fromUtf8(buf)).fileName();
+ buf[len] = 0;
+ return QFileInfo(QFile::decodeName(buf)).fileName();
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
kinfo_proc *proc = kinfo_getproc(pid);
if (!proc)
return QString();
- QString name = QString::fromUtf8(proc->ki_comm);
+ QString name = QFile::decodeName(proc->ki_comm);
free(proc);
return name;
#else