diff options
author | Rafael Roquetto <rafael.roquetto.qnx@kdab.com> | 2012-09-11 17:14:14 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-09-12 17:45:30 (GMT) |
commit | cd8bc427d788071ff10c355647094a8364219ff2 (patch) | |
tree | 455c24c103a320937d7ef380c06aed375fe64c91 | |
parent | a66b95afe3befa0bc43221514832368ed445a7b8 (diff) | |
download | Qt-cd8bc427d788071ff10c355647094a8364219ff2.zip Qt-cd8bc427d788071ff10c355647094a8364219ff2.tar.gz Qt-cd8bc427d788071ff10c355647094a8364219ff2.tar.bz2 |
Fix realpath() call to older POSIX platforms
Some POSIX platforms do not support realpath(X, 0).
This commit is akin to the following qt5 commits:
4a4e9e4a9c56f9b27f2fb76fae6ff06b9f470895
ad5d64226abd50a43856ab560583f37b49ff04c9
6e8e1da0a8267d2f8f568403e6ab9fe53b01cd29
f3707a5a0c4483b15e7bb2ba9f0e7d1913a713ee
Change-Id: I05dc12cedefcaaa11eec2bcc71df023fdb51ac00
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 9476a74..4191f4d 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -180,8 +180,7 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, return QFileSystemEntry(slowCanonicalized(absoluteName(entry).filePath())); #else char *ret = 0; -# if defined(Q_OS_MAC) -# if !defined(QT_NO_CORESERVICES) +# if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES) // Mac OS X 10.5.x doesn't support the realpath(X,0) extension we use here. if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) { ret = realpath(entry.nativeFilePath().constData(), (char*)0); @@ -198,13 +197,19 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, return QFileSystemEntry(ret); } } -# else - ret = (char*)malloc(PATH_MAX); - realpath(entry.nativeFilePath().constData(), (char*)ret); -# endif //!defined(QT_NO_CORESERVICES) -# else +# else +# if _POSIX_VERSION >= 200801L ret = realpath(entry.nativeFilePath().constData(), (char*)0); -# endif //defined(Q_OS_MAC) +# else + ret = (char*)malloc(PATH_MAX + 1); + if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { + const int savedErrno = errno; // errno is checked below, and free() might change it + free(ret); + errno = savedErrno; + ret = 0; + } +# endif +# endif if (ret) { data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute; data.entryFlags |= QFileSystemMetaData::ExistsAttribute; |