-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 | |||
@@ -1,20 +1,20 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
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. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
@@ -42,69 +42,70 @@ | |||
42 | 42 | ||
43 | #include "qdir_p.h" | 43 | #include "qdir_p.h" |
44 | #include "qfileinfo.h" | 44 | #include "qfileinfo.h" |
45 | #include "qregexp.h" | 45 | #include "qregexp.h" |
46 | #include "qstringlist.h" | 46 | #include "qstringlist.h" |
47 | 47 | ||
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 | ||
60 | QString QDir::homeDirPath() | 61 | QString QDir::homeDirPath() |
61 | { | 62 | { |
62 | QString d; | 63 | QString d; |
63 | d = QFile::decodeName(getenv("HOME")); | 64 | d = QFile::decodeName(getenv("HOME")); |
64 | slashify( d ); | 65 | slashify( d ); |
65 | if ( d.isNull() ) | 66 | if ( d.isNull() ) |
66 | d = rootDirPath(); | 67 | d = rootDirPath(); |
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 | } |
105 | 106 | ||
106 | bool QDir::isReadable() const | 107 | bool QDir::isReadable() const |
107 | { | 108 | { |
108 | return ::access( QFile::encodeName(dPath), R_OK | X_OK ) == 0; | 109 | return ::access( QFile::encodeName(dPath), R_OK | X_OK ) == 0; |
109 | } | 110 | } |
110 | 111 | ||
@@ -177,52 +178,56 @@ bool QDir::readDirEntries( const QString &nameFilter, | |||
177 | int i; | 178 | int i; |
178 | if ( !fList ) { | 179 | if ( !fList ) { |
179 | fList = new QStringList; | 180 | fList = new QStringList; |
180 | Q_CHECK_PTR( fList ); | 181 | Q_CHECK_PTR( fList ); |
181 | fiList = new QFileInfoList; | 182 | fiList = new QFileInfoList; |
182 | Q_CHECK_PTR( fiList ); | 183 | Q_CHECK_PTR( fiList ); |
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 ) |
223 | if ( (doReadable && !fi.isReadable()) || | 228 | if ( (doReadable && !fi.isReadable()) || |
224 | (doWritable && !fi.isWritable()) || | 229 | (doWritable && !fi.isWritable()) || |
225 | (doExecable && !fi.isExecutable()) ) | 230 | (doExecable && !fi.isExecutable()) ) |
226 | continue; | 231 | continue; |
227 | if ( !doHidden && fn[0] == '.' && | 232 | if ( !doHidden && fn[0] == '.' && |
228 | fn != QString::fromLatin1(".") | 233 | fn != QString::fromLatin1(".") |
@@ -267,25 +272,26 @@ bool QDir::readDirEntries( const QString &nameFilter, | |||
267 | return TRUE; | 272 | return TRUE; |
268 | } | 273 | } |
269 | 274 | ||
270 | const QFileInfoList * QDir::drives() | 275 | const QFileInfoList * QDir::drives() |
271 | { | 276 | { |
272 | // at most one instance of QFileInfoList is leaked, and this variable | 277 | // at most one instance of QFileInfoList is leaked, and this variable |
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() ) ); |
286 | } | 292 | } |
287 | } | 293 | } |
288 | 294 | ||
289 | return knownMemoryLeak; | 295 | return knownMemoryLeak; |
290 | } | 296 | } |
291 | #endif //QT_NO_DIR | 297 | #endif //QT_NO_DIR |