summaryrefslogtreecommitdiffstats
path: root/qmake/library/ioutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qmake/library/ioutils.cpp')
-rw-r--r--qmake/library/ioutils.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/qmake/library/ioutils.cpp b/qmake/library/ioutils.cpp
index 39264952c6..684bcb9a37 100644
--- a/qmake/library/ioutils.cpp
+++ b/qmake/library/ioutils.cpp
@@ -253,4 +253,39 @@ bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceF
}
#endif
+#ifdef Q_OS_UNIX
+bool IoUtils::readLinkTarget(const QString &symlinkPath, QString *target)
+{
+ const QByteArray localSymlinkPath = QFile::encodeName(symlinkPath);
+# if defined(__GLIBC__) && !defined(PATH_MAX)
+# define PATH_CHUNK_SIZE 256
+ char *s = 0;
+ int len = -1;
+ int size = PATH_CHUNK_SIZE;
+
+ forever {
+ s = (char *)::realloc(s, size);
+ len = ::readlink(localSymlinkPath.constData(), s, size);
+ if (len < 0) {
+ ::free(s);
+ break;
+ }
+ if (len < size)
+ break;
+ size *= 2;
+ }
+# else
+ char s[PATH_MAX+1];
+ int len = readlink(localSymlinkPath.constData(), s, PATH_MAX);
+# endif
+ if (len <= 0)
+ return false;
+ *target = QFile::decodeName(QByteArray(s, len));
+# if defined(__GLIBC__) && !defined(PATH_MAX)
+ ::free(s);
+# endif
+ return true;
+}
+#endif
+
QT_END_NAMESPACE