author | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
commit | 5042e3cf0d3514552769e441f5aad590c8eaf967 (patch) (unidiff) | |
tree | 4a5ea45f3519d981a172ab5275bf38c6fa778dec /qmake/tools/qdir_unix.cpp | |
parent | 108c1c753e74e989cc13923086996791428c9af4 (diff) | |
download | opie-5042e3cf0d3514552769e441f5aad590c8eaf967.zip opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.gz opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.bz2 |
Adding qmake in preperation for new build system
-rw-r--r-- | qmake/tools/qdir_unix.cpp | 291 |
1 files changed, 291 insertions, 0 deletions
diff --git a/qmake/tools/qdir_unix.cpp b/qmake/tools/qdir_unix.cpp new file mode 100644 index 0000000..57fe3c5 --- a/dev/null +++ b/qmake/tools/qdir_unix.cpp | |||
@@ -0,0 +1,291 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Implementation of QDir class | ||
5 | ** | ||
6 | ** Created : 950628 | ||
7 | ** | ||
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | ||
11 | ** | ||
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 | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
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 | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
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 | ||
23 | ** with the Qt Commercial License Agreement provided with the Software. | ||
24 | ** | ||
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. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #include "qplatformdefs.h" | ||
39 | #include "qdir.h" | ||
40 | |||
41 | #ifndef QT_NO_DIR | ||
42 | |||
43 | #include "qdir_p.h" | ||
44 | #include "qfileinfo.h" | ||
45 | #include "qregexp.h" | ||
46 | #include "qstringlist.h" | ||
47 | |||
48 | #ifdef QT_THREAD_SUPPORT | ||
49 | # include <private/qmutexpool_p.h> | ||
50 | #endif // QT_THREAD_SUPPORT | ||
51 | |||
52 | #include <stdlib.h> | ||
53 | #include <limits.h> | ||
54 | |||
55 | |||
56 | void QDir::slashify( QString& ) | ||
57 | { | ||
58 | } | ||
59 | |||
60 | QString QDir::homeDirPath() | ||
61 | { | ||
62 | QString d; | ||
63 | d = QFile::decodeName(getenv("HOME")); | ||
64 | slashify( d ); | ||
65 | if ( d.isNull() ) | ||
66 | d = rootDirPath(); | ||
67 | return d; | ||
68 | } | ||
69 | |||
70 | QString QDir::canonicalPath() const | ||
71 | { | ||
72 | QString r; | ||
73 | |||
74 | char cur[PATH_MAX+1]; | ||
75 | if ( ::getcwd( cur, PATH_MAX ) ) | ||
76 | if ( ::chdir(QFile::encodeName(dPath)) >= 0 ) { | ||
77 | char tmp[PATH_MAX+1]; | ||
78 | if ( ::getcwd( tmp, PATH_MAX ) ) | ||
79 | r = QFile::decodeName(tmp); | ||
80 | ::chdir( cur ); | ||
81 | } | ||
82 | |||
83 | slashify( r ); | ||
84 | return r; | ||
85 | } | ||
86 | |||
87 | bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const | ||
88 | { | ||
89 | #if defined(Q_OS_MACX) // Mac X doesn't support trailing /'s | ||
90 | QString name = dirName; | ||
91 | if (dirName[dirName.length() - 1] == "/") | ||
92 | name = dirName.left( dirName.length() - 1 ); | ||
93 | return ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 ) | ||
94 | == 0; | ||
95 | #else | ||
96 | return ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ) | ||
97 | == 0; | ||
98 | #endif | ||
99 | } | ||
100 | |||
101 | bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const | ||
102 | { | ||
103 | return ::rmdir( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0; | ||
104 | } | ||
105 | |||
106 | bool QDir::isReadable() const | ||
107 | { | ||
108 | return ::access( QFile::encodeName(dPath), R_OK | X_OK ) == 0; | ||
109 | } | ||
110 | |||
111 | bool QDir::isRoot() const | ||
112 | { | ||
113 | return dPath == QString::fromLatin1("/"); | ||
114 | } | ||
115 | |||
116 | bool QDir::rename( const QString &name, const QString &newName, | ||
117 | bool acceptAbsPaths) | ||
118 | { | ||
119 | if ( name.isEmpty() || newName.isEmpty() ) { | ||
120 | #if defined(QT_CHECK_NULL) | ||
121 | qWarning( "QDir::rename: Empty or null file name(s)" ); | ||
122 | #endif | ||
123 | return FALSE; | ||
124 | } | ||
125 | QString fn1 = filePath( name, acceptAbsPaths ); | ||
126 | QString fn2 = filePath( newName, acceptAbsPaths ); | ||
127 | return ::rename( QFile::encodeName(fn1), | ||
128 | QFile::encodeName(fn2) ) == 0; | ||
129 | } | ||
130 | |||
131 | bool QDir::setCurrent( const QString &path ) | ||
132 | { | ||
133 | int r; | ||
134 | r = ::chdir( QFile::encodeName(path) ); | ||
135 | return r >= 0; | ||
136 | } | ||
137 | |||
138 | QString QDir::currentDirPath() | ||
139 | { | ||
140 | QString result; | ||
141 | |||
142 | struct stat st; | ||
143 | if ( ::stat( ".", &st ) == 0 ) { | ||
144 | char currentName[PATH_MAX+1]; | ||
145 | if ( ::getcwd( currentName, PATH_MAX ) ) | ||
146 | result = QFile::decodeName(currentName); | ||
147 | #if defined(QT_DEBUG) | ||
148 | if ( result.isNull() ) | ||
149 | qWarning( "QDir::currentDirPath: getcwd() failed" ); | ||
150 | #endif | ||
151 | } else { | ||
152 | #if defined(QT_DEBUG) | ||
153 | qWarning( "QDir::currentDirPath: stat(\".\") failed" ); | ||
154 | #endif | ||
155 | } | ||
156 | slashify( result ); | ||
157 | return result; | ||
158 | } | ||
159 | |||
160 | QString QDir::rootDirPath() | ||
161 | { | ||
162 | QString d = QString::fromLatin1( "/" ); | ||
163 | return d; | ||
164 | } | ||
165 | |||
166 | bool QDir::isRelativePath( const QString &path ) | ||
167 | { | ||
168 | int len = path.length(); | ||
169 | if ( len == 0 ) | ||
170 | return TRUE; | ||
171 | return path[0] != '/'; | ||
172 | } | ||
173 | |||
174 | bool QDir::readDirEntries( const QString &nameFilter, | ||
175 | int filterSpec, int sortSpec ) | ||
176 | { | ||
177 | int i; | ||
178 | if ( !fList ) { | ||
179 | fList = new QStringList; | ||
180 | Q_CHECK_PTR( fList ); | ||
181 | fiList = new QFileInfoList; | ||
182 | Q_CHECK_PTR( fiList ); | ||
183 | fiList->setAutoDelete( TRUE ); | ||
184 | } else { | ||
185 | fList->clear(); | ||
186 | fiList->clear(); | ||
187 | } | ||
188 | |||
189 | QStringList filters = qt_makeFilterList( nameFilter ); | ||
190 | |||
191 | bool doDirs = (filterSpec & Dirs)!= 0; | ||
192 | bool doFiles = (filterSpec & Files)!= 0; | ||
193 | bool noSymLinks = (filterSpec & NoSymLinks) != 0; | ||
194 | bool doReadable = (filterSpec & Readable)!= 0; | ||
195 | bool doWritable = (filterSpec & Writable)!= 0; | ||
196 | bool doExecable = (filterSpec & Executable) != 0; | ||
197 | bool doHidden = (filterSpec & Hidden)!= 0; | ||
198 | bool doSystem = (filterSpec & System) != 0; | ||
199 | |||
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; | ||
206 | DIR *dir; | ||
207 | dirent *file; | ||
208 | |||
209 | dir = opendir( QFile::encodeName(dPath) ); | ||
210 | if ( !dir ) | ||
211 | return FALSE; // cannot read the directory | ||
212 | |||
213 | while ( (file = readdir(dir)) ) { | ||
214 | QString fn = QFile::decodeName(file->d_name); | ||
215 | fi.setFile( *this, fn ); | ||
216 | if ( !match( filters, fn ) && !(allDirs && fi.isDir()) ) | ||
217 | continue; | ||
218 | if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) || | ||
219 | (doSystem && (!fi.isFile() && !fi.isDir())) ) { | ||
220 | if ( noSymLinks && fi.isSymLink() ) | ||
221 | continue; | ||
222 | if ( (filterSpec & RWEMask) != 0 ) | ||
223 | if ( (doReadable && !fi.isReadable()) || | ||
224 | (doWritable && !fi.isWritable()) || | ||
225 | (doExecable && !fi.isExecutable()) ) | ||
226 | continue; | ||
227 | if ( !doHidden && fn[0] == '.' && | ||
228 | fn != QString::fromLatin1(".") | ||
229 | && fn != QString::fromLatin1("..") ) | ||
230 | continue; | ||
231 | fiList->append( new QFileInfo( fi ) ); | ||
232 | } | ||
233 | } | ||
234 | if ( closedir(dir) != 0 ) { | ||
235 | #if defined(QT_CHECK_NULL) | ||
236 | qWarning( "QDir::readDirEntries: Cannot close the directory: %s", | ||
237 | dPath.local8Bit().data() ); | ||
238 | #endif | ||
239 | } | ||
240 | |||
241 | // Sort... | ||
242 | if(fiList->count()) { | ||
243 | QDirSortItem* si= new QDirSortItem[fiList->count()]; | ||
244 | QFileInfo* itm; | ||
245 | i=0; | ||
246 | for (itm = fiList->first(); itm; itm = fiList->next()) | ||
247 | si[i++].item = itm; | ||
248 | qt_cmp_si_sortSpec = sortSpec; | ||
249 | qsort( si, i, sizeof(si[0]), qt_cmp_si ); | ||
250 | // put them back in the list | ||
251 | fiList->setAutoDelete( FALSE ); | ||
252 | fiList->clear(); | ||
253 | int j; | ||
254 | for ( j=0; j<i; j++ ) { | ||
255 | fiList->append( si[j].item ); | ||
256 | fList->append( si[j].item->fileName() ); | ||
257 | } | ||
258 | delete [] si; | ||
259 | fiList->setAutoDelete( TRUE ); | ||
260 | } | ||
261 | |||
262 | if ( filterSpec == (FilterSpec)filtS && sortSpec == (SortSpec)sortS && | ||
263 | nameFilter == nameFilt ) | ||
264 | dirty = FALSE; | ||
265 | else | ||
266 | dirty = TRUE; | ||
267 | return TRUE; | ||
268 | } | ||
269 | |||
270 | const QFileInfoList * QDir::drives() | ||
271 | { | ||
272 | // at most one instance of QFileInfoList is leaked, and this variable | ||
273 | // points to that list | ||
274 | static QFileInfoList * knownMemoryLeak = 0; | ||
275 | |||
276 | if ( !knownMemoryLeak ) { | ||
277 | |||
278 | #ifdef QT_THREAD_SUPPORT | ||
279 | QMutexLocker locker( qt_global_mutexpool->get( &knownMemoryLeak ) ); | ||
280 | #endif // QT_THREAD_SUPPORT | ||
281 | |||
282 | if ( !knownMemoryLeak ) { | ||
283 | knownMemoryLeak = new QFileInfoList; | ||
284 | // non-win32 versions both use just one root directory | ||
285 | knownMemoryLeak->append( new QFileInfo( rootDirPath() ) ); | ||
286 | } | ||
287 | } | ||
288 | |||
289 | return knownMemoryLeak; | ||
290 | } | ||
291 | #endif //QT_NO_DIR | ||