diff --git a/src/corelib/io/qfiledevice_p.h b/src/corelib/io/qfiledevice_p.h index aef3fca811..9adba680d7 100644 --- a/src/corelib/io/qfiledevice_p.h +++ b/src/corelib/io/qfiledevice_p.h @@ -54,6 +54,10 @@ #include "private/qiodevice_p.h" #include +#ifdef Q_OS_UNIX +# include // for mode_t +# include // for mode_t constants +#endif QT_BEGIN_NAMESPACE @@ -98,6 +102,36 @@ inline bool QFileDevicePrivate::ensureFlushed() const return true; } +#ifdef Q_OS_UNIX +namespace QtPrivate { + +constexpr mode_t toMode_t(QFileDevice::Permissions permissions) +{ + mode_t mode = 0; + if (permissions & (QFileDevice::ReadOwner | QFileDevice::ReadUser)) + mode |= S_IRUSR; + if (permissions & (QFileDevice::WriteOwner | QFileDevice::WriteUser)) + mode |= S_IWUSR; + if (permissions & (QFileDevice::ExeOwner | QFileDevice::ExeUser)) + mode |= S_IXUSR; + if (permissions & QFileDevice::ReadGroup) + mode |= S_IRGRP; + if (permissions & QFileDevice::WriteGroup) + mode |= S_IWGRP; + if (permissions & QFileDevice::ExeGroup) + mode |= S_IXGRP; + if (permissions & QFileDevice::ReadOther) + mode |= S_IROTH; + if (permissions & QFileDevice::WriteOther) + mode |= S_IWOTH; + if (permissions & QFileDevice::ExeOther) + mode |= S_IXOTH; + return mode; +} + +} // namespace QtPrivate +#endif // Q_OS_UNIX + QT_END_NAMESPACE #endif // QFILEDEVICE_P_H diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 054e9ed2fe..8c2df84b72 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #ifndef QT_BOOTSTRAPPED # include @@ -53,8 +54,6 @@ #include #include // for realpath() -#include -#include #include #include #include @@ -1527,36 +1526,12 @@ bool QFileSystemEngine::removeFile(const QFileSystemEntry &entry, QSystemError & } -static mode_t toMode_t(QFile::Permissions permissions) -{ - mode_t mode = 0; - if (permissions & (QFile::ReadOwner | QFile::ReadUser)) - mode |= S_IRUSR; - if (permissions & (QFile::WriteOwner | QFile::WriteUser)) - mode |= S_IWUSR; - if (permissions & (QFile::ExeOwner | QFile::ExeUser)) - mode |= S_IXUSR; - if (permissions & QFile::ReadGroup) - mode |= S_IRGRP; - if (permissions & QFile::WriteGroup) - mode |= S_IWGRP; - if (permissions & QFile::ExeGroup) - mode |= S_IXGRP; - if (permissions & QFile::ReadOther) - mode |= S_IROTH; - if (permissions & QFile::WriteOther) - mode |= S_IWOTH; - if (permissions & QFile::ExeOther) - mode |= S_IXOTH; - return mode; -} - //static bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) { Q_CHECK_FILE_NAME(entry, false); - mode_t mode = toMode_t(permissions); + mode_t mode = QtPrivate::toMode_t(permissions); bool success = ::chmod(entry.nativeFilePath().constData(), mode) == 0; if (success && data) { data->entryFlags &= ~QFileSystemMetaData::Permissions; @@ -1571,7 +1546,7 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per //static bool QFileSystemEngine::setPermissions(int fd, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data) { - mode_t mode = toMode_t(permissions); + mode_t mode = QtPrivate::toMode_t(permissions); bool success = ::fchmod(fd, mode) == 0; if (success && data) {