-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,122 +1,123 @@ | |||
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 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses for Unix/X11 or for Qt/Embedded may use this file in accordance | 22 | ** licenses for Unix/X11 or for Qt/Embedded may use this file in accordance |
23 | ** with the Qt Commercial License Agreement provided with the Software. | 23 | ** with the Qt Commercial License Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #include "qplatformdefs.h" | 38 | #include "qplatformdefs.h" |
39 | #include "qdir.h" | 39 | #include "qdir.h" |
40 | 40 | ||
41 | #ifndef QT_NO_DIR | 41 | #ifndef QT_NO_DIR |
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 | ||
111 | bool QDir::isRoot() const | 112 | bool QDir::isRoot() const |
112 | { | 113 | { |
113 | return dPath == QString::fromLatin1("/"); | 114 | return dPath == QString::fromLatin1("/"); |
114 | } | 115 | } |
115 | 116 | ||
116 | bool QDir::rename( const QString &name, const QString &newName, | 117 | bool QDir::rename( const QString &name, const QString &newName, |
117 | bool acceptAbsPaths) | 118 | bool acceptAbsPaths) |
118 | { | 119 | { |
119 | if ( name.isEmpty() || newName.isEmpty() ) { | 120 | if ( name.isEmpty() || newName.isEmpty() ) { |
120 | #if defined(QT_CHECK_NULL) | 121 | #if defined(QT_CHECK_NULL) |
121 | qWarning( "QDir::rename: Empty or null file name(s)" ); | 122 | qWarning( "QDir::rename: Empty or null file name(s)" ); |
122 | #endif | 123 | #endif |
@@ -165,76 +166,80 @@ QString QDir::rootDirPath() | |||
165 | 166 | ||
166 | bool QDir::isRelativePath( const QString &path ) | 167 | bool QDir::isRelativePath( const QString &path ) |
167 | { | 168 | { |
168 | int len = path.length(); | 169 | int len = path.length(); |
169 | if ( len == 0 ) | 170 | if ( len == 0 ) |
170 | return TRUE; | 171 | return TRUE; |
171 | return path[0] != '/'; | 172 | return path[0] != '/'; |
172 | } | 173 | } |
173 | 174 | ||
174 | bool QDir::readDirEntries( const QString &nameFilter, | 175 | bool QDir::readDirEntries( const QString &nameFilter, |
175 | int filterSpec, int sortSpec ) | 176 | int filterSpec, int sortSpec ) |
176 | { | 177 | { |
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(".") |
229 | && fn != QString::fromLatin1("..") ) | 234 | && fn != QString::fromLatin1("..") ) |
230 | continue; | 235 | continue; |
231 | fiList->append( new QFileInfo( fi ) ); | 236 | fiList->append( new QFileInfo( fi ) ); |
232 | } | 237 | } |
233 | } | 238 | } |
234 | if ( closedir(dir) != 0 ) { | 239 | if ( closedir(dir) != 0 ) { |
235 | #if defined(QT_CHECK_NULL) | 240 | #if defined(QT_CHECK_NULL) |
236 | qWarning( "QDir::readDirEntries: Cannot close the directory: %s", | 241 | qWarning( "QDir::readDirEntries: Cannot close the directory: %s", |
237 | dPath.local8Bit().data() ); | 242 | dPath.local8Bit().data() ); |
238 | #endif | 243 | #endif |
239 | } | 244 | } |
240 | 245 | ||
@@ -255,37 +260,38 @@ bool QDir::readDirEntries( const QString &nameFilter, | |||
255 | fiList->append( si[j].item ); | 260 | fiList->append( si[j].item ); |
256 | fList->append( si[j].item->fileName() ); | 261 | fList->append( si[j].item->fileName() ); |
257 | } | 262 | } |
258 | delete [] si; | 263 | delete [] si; |
259 | fiList->setAutoDelete( TRUE ); | 264 | fiList->setAutoDelete( TRUE ); |
260 | } | 265 | } |
261 | 266 | ||
262 | if ( filterSpec == (FilterSpec)filtS && sortSpec == (SortSpec)sortS && | 267 | if ( filterSpec == (FilterSpec)filtS && sortSpec == (SortSpec)sortS && |
263 | nameFilter == nameFilt ) | 268 | nameFilter == nameFilt ) |
264 | dirty = FALSE; | 269 | dirty = FALSE; |
265 | else | 270 | else |
266 | dirty = TRUE; | 271 | dirty = TRUE; |
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 |