From kde-commits Sat Aug 16 21:23:01 2003 From: Julian Rockey Date: Sat, 16 Aug 2003 21:23:01 +0000 To: kde-commits Subject: kdevelop/lib/util X-MARC-Message: https://marc.info/?l=kde-commits&m=106106901530871 CVS commit by jrockey: canonicalPath for use for all QT version M +23 -0 urlutil.cpp 1.10 M +8 -0 urlutil.h 1.8 --- kdevelop/lib/util/urlutil.cpp #1.9:1.10 @@ -18,4 +18,7 @@ #include #include +#include + +#include #include "urlutil.h" @@ -190,2 +193,22 @@ QString URLUtil::relativePathToFile( con return result_up + result_down + resFileName; } + +// code from qt-3.1.2 version of QDir::canonicalPath() + +QString URLUtil::canonicalPath( const QString & path ) +{ + QString r; + char cur[PATH_MAX+1]; + if ( ::getcwd( cur, PATH_MAX ) ) + { + char tmp[PATH_MAX+1]; + if( ::realpath( QFile::encodeName( path ), tmp ) ) + { + r = QFile::decodeName( tmp ); + } + //always make sure we go back to the current dir + ::chdir( cur ); + } + return r; +} + --- kdevelop/lib/util/urlutil.h #1.7:1.8 @@ -103,4 +103,12 @@ namespace URLUtil */ void dump( const KURL::List &urls, const QString &aMessage = QString::null ); + + /** + * Same as QDir::canonicalPath in later versions of QT. Earlier versions of QT + * had this broken, so it's reproduced here. + */ + QString canonicalPath( const QString & path ); + + };