From cd8bc427d788071ff10c355647094a8364219ff2 Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Tue, 11 Sep 2012 14:14:14 -0300 Subject: 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 Reviewed-by: Thomas McGuire Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemengine_unix.cpp | 21 +++++++++++++-------- 1 file 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; -- cgit v0.12