42 #include "qplatformdefs.h" 44 #include "qplatformdefs.h" 48 #include <QtCore/qvarlengtharray.h> 57 # include <QtCore/private/qcore_mac_p.h> 62 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) 68 err = FSPathMakeRefWithOptions(reinterpret_cast<const UInt8 *>(nativePath),
69 kFSPathMakeRefDoNotFollowLeafSymlink, &fsRef, 0);
73 FSCatalogInfo catInfo;
74 err = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL);
78 FileInfo *
const fileInfo =
reinterpret_cast<FileInfo*
>(&catInfo.finderInfo);
79 return (fileInfo->finderFlags & kIsInvisible);
98 #if defined(__GLIBC__) && !defined(PATH_MAX) 99 #define PATH_CHUNK_SIZE 256 102 int size = PATH_CHUNK_SIZE;
105 s = (
char *) ::realloc(s, size);
134 #if defined(__GLIBC__) && !defined(PATH_MAX) 151 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) 157 if (FSResolveAliasFile(&fref,
true, &isFolder, &isAlias) == noErr && isAlias) {
159 if (FSNewAlias(0, &fref, &alias) == noErr && alias) {
161 if (FSCopyAliasInfo(alias, 0, 0, &cfstr, 0, 0) == noErr)
177 #if !defined(Q_OS_MAC) && !defined(Q_OS_QNX) && _POSIX_VERSION < 200809L 183 # if defined(Q_OS_MAC) && !defined(Q_OS_IOS) 189 const int savedErrno =
errno;
198 if (FSPathMakeRef((
const UInt8 *)path.
toUtf8().
data(), &fsref, 0) == noErr) {
199 CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref);
200 CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle);
202 CFRelease(canonicalPath);
208 # if _POSIX_VERSION >= 200801L 213 const int savedErrno =
errno;
226 }
else if (
errno == ENOENT) {
247 if (!orig.
isEmpty() && !(orig.
length() == 1 && orig[0] ==
'.')) {
253 if (result.
length() == 1 && result[0] ==
'/')
255 const bool isDir = result.
endsWith(
'/');
271 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) 272 int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
278 struct passwd *pw = 0;
279 #if !defined(Q_OS_INTEGRITY) 280 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_VXWORKS) 282 getpwuid_r(userId, &entry, buf.
data(), buf.
size(), &pw);
284 pw = getpwuid(userId);
295 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) 296 int size_max = sysconf(_SC_GETPW_R_SIZE_MAX);
302 struct group *gr = 0;
303 #if !defined(Q_OS_INTEGRITY) 304 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_VXWORKS) 305 size_max = sysconf(_SC_GETGR_R_SIZE_MAX);
312 for (
unsigned size = size_max; size < 256000; size += size)
316 if (!getgrgid_r(groupId, &entry, buf.
data(), buf.
size(), &gr)
321 gr = getgrgid(groupId);
329 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) 334 kCFURLPOSIXPathStyle,
true);
337 if (CFGetTypeID(
name) == CFStringGetTypeID())
347 QFileSystemMetaData::MetaDataFlags what)
349 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) 356 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) \ 357 && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 374 const char * nativeFilePath;
375 int nativeFilePathLength;
379 nativeFilePathLength = path.
size();
383 bool entryExists =
true;
385 QT_STATBUF statBuffer;
386 bool statBufferValid =
false;
388 if (QT_LSTAT(nativeFilePath, &statBuffer) == 0) {
389 if (
S_ISLNK(statBuffer.st_mode)) {
392 statBufferValid =
true;
402 if (statBufferValid || (what & QFileSystemMetaData::PosixStatFlags)) {
403 if (entryExists && !statBufferValid)
404 statBufferValid = (QT_STAT(nativeFilePath, &statBuffer) == 0);
411 data.modificationTime_ = 0;
412 data.accessTime_ = 0;
414 data.userId_ = (
uint) -2;
415 data.groupId_ = (
uint) -2;
423 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) 428 if (FSPathMakeRef((
const UInt8 *)nativeFilePath, &fref, NULL) == noErr) {
430 if (FSIsAliasFile(&fref, &isAlias, &isFolder) == noErr) {
445 if (QT_ACCESS(nativeFilePath, R_OK) == 0)
446 data.
entryFlags |= QFileSystemMetaData::UserReadPermission;
449 if (QT_ACCESS(nativeFilePath, W_OK) == 0)
450 data.
entryFlags |= QFileSystemMetaData::UserWritePermission;
453 if (QT_ACCESS(nativeFilePath, X_OK) == 0)
454 data.
entryFlags |= QFileSystemMetaData::UserExecutePermission;
460 if (what & QFileSystemMetaData::HiddenAttribute
469 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC) 470 if (what & QFileSystemMetaData::BundleType) {
473 (
const UInt8*)nativeFilePath, nativeFilePathLength,
474 kCFStringEncodingUTF8,
false);
476 kCFURLPOSIXPathStyle,
true);
478 UInt32
type, creator;
479 if (CFBundleGetPackageInfoInDirectory(url, &type, &creator))
496 for (
int oldslash = -1, slash=0; slash != -1; oldslash = slash) {
499 if (oldslash == dirName.
length())
506 if (QT_STAT(chunk, &st) != -1) {
509 }
else if (QT_MKDIR(chunk, 0777) != 0) {
516 #if defined(Q_OS_DARWIN) // Mac X doesn't support trailing /'s 526 if (removeEmptyParents) {
528 for (
int oldslash = 0, slash=dirName.
length(); slash > 0; oldslash = slash) {
531 if (QT_STAT(chunk, &st) != -1) {
534 if (::rmdir(chunk) != 0)
535 return oldslash != 0;
613 if (success && data) {
638 #ifdef QT_UNIX_TEMP_PATH_OVERRIDE 640 #elif defined(Q_OS_BLACKBERRY) 646 qWarning(
"Neither the TEMP nor the TMPDIR environment variable is set, falling back to /tmp.");
669 if (QT_STAT(
".", &st) == 0) {
670 #if defined(__GLIBC__) && !defined(PATH_MAX) 671 char *currentName = ::get_current_dir_name();
678 if (::getcwd(currentName,
PATH_MAX)) {
679 #if defined(Q_OS_VXWORKS) && defined(VXWORKS_VXSIM) 688 # if defined(QT_DEBUG) 690 qWarning(
"QFSFileEngine::currentPath: getcwd() failed");
694 # if defined(QT_DEBUG) 695 qWarning(
"QFSFileEngine::currentPath: stat(\".\") failed");
The QDir class provides access to directory structures and their contents.
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
const struct __CFString * CFStringRef
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data=0)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
#define QT_END_NAMESPACE
This macro expands to.
static QString rootPath()
char * data()
Returns a pointer to the data stored in the byte array.
const QChar at(int i) const
Returns the character at the given index position in the string.
QByteArray & append(char c)
Appends the character ch to this byte array.
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
static QString resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
The QByteArray class provides an array of bytes.
void chop(int n)
Removes n characters from the end of the string.
int length() const
Returns the number of characters in this string.
QString & prepend(QChar c)
static QString toQString(CFStringRef cfstr)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
static QString currentPath()
Returns the absolute path of the application's current directory.
static bool isCaseSensitive()
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
static QFileSystemEntry currentPath()
NativePath nativeFilePath() const
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
bool cdUp()
Changes directory by moving one directory up from the QDir's current directory.
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QString tempPath()
static QString resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString slowCanonicalized(const QString &path)
Returns the canonicalized form of path (i.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
static QFileSystemEntry getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
static bool createDirectory(const QFileSystemEntry &entry, bool createParents)
static QString bundleName(const QFileSystemEntry &entry)
int length() const
Same as size().
const char * constData() const
Returns a pointer to the data stored in the byte array.
static bool _q_isMacHidden(const char *nativePath)
static bool setCurrentPath(const QFileSystemEntry &entry)
static bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
QString & append(QChar c)
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static bool removeFile(const QFileSystemEntry &entry, QSystemError &error)
#define st(var, type, card)
static QString homePath()
int size() const
Returns the number of bytes in this byte array.
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Q_CORE_EXPORT char * qstrncpy(char *dst, const char *src, uint len)
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)