-rw-r--r-- | qmake/tools/qdir_unix.cpp | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/qmake/tools/qdir_unix.cpp b/qmake/tools/qdir_unix.cpp index 57fe3c5..6a7adda 100644 --- a/qmake/tools/qdir_unix.cpp +++ b/qmake/tools/qdir_unix.cpp | |||
@@ -2,13 +2,13 @@ | |||
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of QDir class | 4 | ** Implementation of QDir class |
5 | ** | 5 | ** |
6 | ** Created : 950628 | 6 | ** Created : 950628 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
@@ -48,12 +48,13 @@ | |||
48 | #ifdef QT_THREAD_SUPPORT | 48 | #ifdef QT_THREAD_SUPPORT |
49 | # include <private/qmutexpool_p.h> | 49 | # include <private/qmutexpool_p.h> |
50 | #endif // QT_THREAD_SUPPORT | 50 | #endif // QT_THREAD_SUPPORT |
51 | 51 | ||
52 | #include <stdlib.h> | 52 | #include <stdlib.h> |
53 | #include <limits.h> | 53 | #include <limits.h> |
54 | #include <errno.h> | ||
54 | 55 | ||
55 | 56 | ||
56 | void QDir::slashify( QString& ) | 57 | void QDir::slashify( QString& ) |
57 | { | 58 | { |
58 | } | 59 | } |
59 | 60 | ||
@@ -67,38 +68,38 @@ QString QDir::homeDirPath() | |||
67 | return d; | 68 | return d; |
68 | } | 69 | } |
69 | 70 | ||
70 | QString QDir::canonicalPath() const | 71 | QString QDir::canonicalPath() const |
71 | { | 72 | { |
72 | QString r; | 73 | QString r; |
73 | |||
74 | char cur[PATH_MAX+1]; | 74 | char cur[PATH_MAX+1]; |
75 | if ( ::getcwd( cur, PATH_MAX ) ) | 75 | if ( ::getcwd( cur, PATH_MAX ) ) { |
76 | if ( ::chdir(QFile::encodeName(dPath)) >= 0 ) { | 76 | char tmp[PATH_MAX+1]; |
77 | char tmp[PATH_MAX+1]; | 77 | if( ::realpath( QFile::encodeName( dPath ), tmp ) ) |
78 | if ( ::getcwd( tmp, PATH_MAX ) ) | 78 | r = QFile::decodeName( tmp ); |
79 | r = QFile::decodeName(tmp); | 79 | slashify( r ); |
80 | ::chdir( cur ); | 80 | |
81 | } | 81 | // always make sure we go back to the current dir |
82 | 82 | ::chdir( cur ); | |
83 | slashify( r ); | 83 | } |
84 | return r; | 84 | return r; |
85 | } | 85 | } |
86 | 86 | ||
87 | bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const | 87 | bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const |
88 | { | 88 | { |
89 | #if defined(Q_OS_MACX) // Mac X doesn't support trailing /'s | 89 | #if defined(Q_OS_MACX) // Mac X doesn't support trailing /'s |
90 | QString name = dirName; | 90 | QString name = dirName; |
91 | if (dirName[dirName.length() - 1] == "/") | 91 | if (dirName[dirName.length() - 1] == "/") |
92 | name = dirName.left( dirName.length() - 1 ); | 92 | name = dirName.left( dirName.length() - 1 ); |
93 | return ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 ) | 93 | int status = |
94 | == 0; | 94 | ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 ); |
95 | #else | 95 | #else |
96 | return ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ) | 96 | int status = |
97 | == 0; | 97 | ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ); |
98 | #endif | 98 | #endif |
99 | return status == 0; | ||
99 | } | 100 | } |
100 | 101 | ||
101 | bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const | 102 | bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const |
102 | { | 103 | { |
103 | return ::rmdir( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0; | 104 | return ::rmdir( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0; |
104 | } | 105 | } |
@@ -183,40 +184,44 @@ bool QDir::readDirEntries( const QString &nameFilter, | |||
183 | fiList->setAutoDelete( TRUE ); | 184 | fiList->setAutoDelete( TRUE ); |
184 | } else { | 185 | } else { |
185 | fList->clear(); | 186 | fList->clear(); |
186 | fiList->clear(); | 187 | fiList->clear(); |
187 | } | 188 | } |
188 | 189 | ||
189 | QStringList filters = qt_makeFilterList( nameFilter ); | 190 | QValueList<QRegExp> filters = qt_makeFilterList( nameFilter ); |
190 | 191 | ||
191 | bool doDirs = (filterSpec & Dirs)!= 0; | 192 | bool doDirs = (filterSpec & Dirs)!= 0; |
192 | bool doFiles = (filterSpec & Files)!= 0; | 193 | bool doFiles = (filterSpec & Files)!= 0; |
193 | bool noSymLinks = (filterSpec & NoSymLinks) != 0; | 194 | bool noSymLinks = (filterSpec & NoSymLinks) != 0; |
194 | bool doReadable = (filterSpec & Readable)!= 0; | 195 | bool doReadable = (filterSpec & Readable)!= 0; |
195 | bool doWritable = (filterSpec & Writable)!= 0; | 196 | bool doWritable = (filterSpec & Writable)!= 0; |
196 | bool doExecable = (filterSpec & Executable) != 0; | 197 | bool doExecable = (filterSpec & Executable) != 0; |
197 | bool doHidden = (filterSpec & Hidden)!= 0; | 198 | bool doHidden = (filterSpec & Hidden)!= 0; |
198 | bool doSystem = (filterSpec & System) != 0; | 199 | bool doSystem = (filterSpec & System) != 0; |
199 | 200 | ||
200 | #if defined(Q_OS_OS2EMX) | ||
201 | //QRegExp wc( nameFilter, FALSE, TRUE );// wild card, case insensitive | ||
202 | #else | ||
203 | //QRegExp wc( nameFilter, TRUE, TRUE );// wild card, case sensitive | ||
204 | #endif | ||
205 | QFileInfo fi; | 201 | QFileInfo fi; |
206 | DIR *dir; | 202 | DIR *dir; |
207 | dirent *file; | 203 | dirent *file; |
208 | 204 | ||
209 | dir = opendir( QFile::encodeName(dPath) ); | 205 | dir = opendir( QFile::encodeName(dPath) ); |
210 | if ( !dir ) | 206 | if ( !dir ) |
211 | return FALSE; // cannot read the directory | 207 | return FALSE; // cannot read the directory |
212 | 208 | ||
213 | while ( (file = readdir(dir)) ) { | 209 | #if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) |
210 | union { | ||
211 | struct dirent mt_file; | ||
212 | char b[sizeof(struct dirent) + MAXNAMLEN + 1]; | ||
213 | } u; | ||
214 | while ( readdir_r(dir, &u.mt_file, &file ) == 0 && file ) | ||
215 | #else | ||
216 | while ( (file = readdir(dir)) ) | ||
217 | #endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS | ||
218 | { | ||
214 | QString fn = QFile::decodeName(file->d_name); | 219 | QString fn = QFile::decodeName(file->d_name); |
215 | fi.setFile( *this, fn ); | 220 | fi.setFile( *this, fn ); |
216 | if ( !match( filters, fn ) && !(allDirs && fi.isDir()) ) | 221 | if ( !qt_matchFilterList(filters, fn) && !(allDirs && fi.isDir()) ) |
217 | continue; | 222 | continue; |
218 | if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) || | 223 | if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) || |
219 | (doSystem && (!fi.isFile() && !fi.isDir())) ) { | 224 | (doSystem && (!fi.isFile() && !fi.isDir())) ) { |
220 | if ( noSymLinks && fi.isSymLink() ) | 225 | if ( noSymLinks && fi.isSymLink() ) |
221 | continue; | 226 | continue; |
222 | if ( (filterSpec & RWEMask) != 0 ) | 227 | if ( (filterSpec & RWEMask) != 0 ) |
@@ -273,13 +278,14 @@ const QFileInfoList * QDir::drives() | |||
273 | // points to that list | 278 | // points to that list |
274 | static QFileInfoList * knownMemoryLeak = 0; | 279 | static QFileInfoList * knownMemoryLeak = 0; |
275 | 280 | ||
276 | if ( !knownMemoryLeak ) { | 281 | if ( !knownMemoryLeak ) { |
277 | 282 | ||
278 | #ifdef QT_THREAD_SUPPORT | 283 | #ifdef QT_THREAD_SUPPORT |
279 | QMutexLocker locker( qt_global_mutexpool->get( &knownMemoryLeak ) ); | 284 | QMutexLocker locker( qt_global_mutexpool ? |
285 | qt_global_mutexpool->get( &knownMemoryLeak ) : 0 ); | ||
280 | #endif // QT_THREAD_SUPPORT | 286 | #endif // QT_THREAD_SUPPORT |
281 | 287 | ||
282 | if ( !knownMemoryLeak ) { | 288 | if ( !knownMemoryLeak ) { |
283 | knownMemoryLeak = new QFileInfoList; | 289 | knownMemoryLeak = new QFileInfoList; |
284 | // non-win32 versions both use just one root directory | 290 | // non-win32 versions both use just one root directory |
285 | knownMemoryLeak->append( new QFileInfo( rootDirPath() ) ); | 291 | knownMemoryLeak->append( new QFileInfo( rootDirPath() ) ); |