summaryrefslogtreecommitdiff
path: root/qmake/tools/qdir_unix.cpp
Side-by-side diff
Diffstat (limited to 'qmake/tools/qdir_unix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qdir_unix.cpp54
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 @@
/****************************************************************************
** $Id$
**
** Implementation of QDir class
**
** Created : 950628
**
-** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
+** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
@@ -42,69 +42,70 @@
#include "qdir_p.h"
#include "qfileinfo.h"
#include "qregexp.h"
#include "qstringlist.h"
#ifdef QT_THREAD_SUPPORT
# include <private/qmutexpool_p.h>
#endif // QT_THREAD_SUPPORT
#include <stdlib.h>
#include <limits.h>
+#include <errno.h>
void QDir::slashify( QString& )
{
}
QString QDir::homeDirPath()
{
QString d;
d = QFile::decodeName(getenv("HOME"));
slashify( d );
if ( d.isNull() )
d = rootDirPath();
return d;
}
QString QDir::canonicalPath() const
{
QString r;
-
char cur[PATH_MAX+1];
- if ( ::getcwd( cur, PATH_MAX ) )
- if ( ::chdir(QFile::encodeName(dPath)) >= 0 ) {
- char tmp[PATH_MAX+1];
- if ( ::getcwd( tmp, PATH_MAX ) )
- r = QFile::decodeName(tmp);
- ::chdir( cur );
- }
-
- slashify( r );
+ if ( ::getcwd( cur, PATH_MAX ) ) {
+ char tmp[PATH_MAX+1];
+ if( ::realpath( QFile::encodeName( dPath ), tmp ) )
+ r = QFile::decodeName( tmp );
+ slashify( r );
+
+ // always make sure we go back to the current dir
+ ::chdir( cur );
+ }
return r;
}
bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const
{
#if defined(Q_OS_MACX) // Mac X doesn't support trailing /'s
QString name = dirName;
if (dirName[dirName.length() - 1] == "/")
name = dirName.left( dirName.length() - 1 );
- return ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 )
- == 0;
+ int status =
+ ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 );
#else
- return ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 )
- == 0;
+ int status =
+ ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 );
#endif
+ return status == 0;
}
bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const
{
return ::rmdir( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0;
}
bool QDir::isReadable() const
{
return ::access( QFile::encodeName(dPath), R_OK | X_OK ) == 0;
}
@@ -177,52 +178,56 @@ bool QDir::readDirEntries( const QString &nameFilter,
int i;
if ( !fList ) {
fList = new QStringList;
Q_CHECK_PTR( fList );
fiList = new QFileInfoList;
Q_CHECK_PTR( fiList );
fiList->setAutoDelete( TRUE );
} else {
fList->clear();
fiList->clear();
}
- QStringList filters = qt_makeFilterList( nameFilter );
+ QValueList<QRegExp> filters = qt_makeFilterList( nameFilter );
bool doDirs = (filterSpec & Dirs) != 0;
bool doFiles = (filterSpec & Files) != 0;
bool noSymLinks = (filterSpec & NoSymLinks) != 0;
bool doReadable = (filterSpec & Readable) != 0;
bool doWritable = (filterSpec & Writable) != 0;
bool doExecable = (filterSpec & Executable) != 0;
bool doHidden = (filterSpec & Hidden) != 0;
bool doSystem = (filterSpec & System) != 0;
-#if defined(Q_OS_OS2EMX)
- //QRegExp wc( nameFilter, FALSE, TRUE ); // wild card, case insensitive
-#else
- //QRegExp wc( nameFilter, TRUE, TRUE ); // wild card, case sensitive
-#endif
QFileInfo fi;
DIR *dir;
dirent *file;
dir = opendir( QFile::encodeName(dPath) );
if ( !dir )
return FALSE; // cannot read the directory
- while ( (file = readdir(dir)) ) {
+#if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN)
+ union {
+ struct dirent mt_file;
+ char b[sizeof(struct dirent) + MAXNAMLEN + 1];
+ } u;
+ while ( readdir_r(dir, &u.mt_file, &file ) == 0 && file )
+#else
+ while ( (file = readdir(dir)) )
+#endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS
+ {
QString fn = QFile::decodeName(file->d_name);
fi.setFile( *this, fn );
- if ( !match( filters, fn ) && !(allDirs && fi.isDir()) )
+ if ( !qt_matchFilterList(filters, fn) && !(allDirs && fi.isDir()) )
continue;
if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) ||
(doSystem && (!fi.isFile() && !fi.isDir())) ) {
if ( noSymLinks && fi.isSymLink() )
continue;
if ( (filterSpec & RWEMask) != 0 )
if ( (doReadable && !fi.isReadable()) ||
(doWritable && !fi.isWritable()) ||
(doExecable && !fi.isExecutable()) )
continue;
if ( !doHidden && fn[0] == '.' &&
fn != QString::fromLatin1(".")
@@ -267,25 +272,26 @@ bool QDir::readDirEntries( const QString &nameFilter,
return TRUE;
}
const QFileInfoList * QDir::drives()
{
// at most one instance of QFileInfoList is leaked, and this variable
// points to that list
static QFileInfoList * knownMemoryLeak = 0;
if ( !knownMemoryLeak ) {
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &knownMemoryLeak ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &knownMemoryLeak ) : 0 );
#endif // QT_THREAD_SUPPORT
if ( !knownMemoryLeak ) {
knownMemoryLeak = new QFileInfoList;
// non-win32 versions both use just one root directory
knownMemoryLeak->append( new QFileInfo( rootDirPath() ) );
}
}
return knownMemoryLeak;
}
#endif //QT_NO_DIR