Fix warnings from deprecated posix functions

Windows wants ISO C++ _fileno and _unlink instead of posix fileno and
unlink. For fileno we have the QT_FILENO macro in qplatformdefs.h, so use
it. For unlink we don't have a macro in Qt, so declare one in the test.

Change-Id: I56c5c3fb4e500769c744132c46107816f89bb2c3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Volker Hilsheimer 2021-04-27 16:31:08 +02:00
parent 069369d867
commit bbc385150f
2 changed files with 6 additions and 4 deletions

View File

@ -1766,7 +1766,7 @@ void tst_QFile::largeUncFileSupport()
// Retry in case of sharing violation
QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF));
StdioFileGuard fh(fhF);
int fd = int(_fileno(fh));
int fd = int(QT_FILENO(fh));
QFile file;
QVERIFY(file.open(fd, QIODevice::ReadOnly));
QCOMPARE(file.size(), size);
@ -2854,8 +2854,8 @@ void tst_QFile::handle()
StdioFileGuard fp(fopen(qPrintable(m_testSourceFile), "r"));
QVERIFY(fp);
file2.open(fp, QIODevice::ReadOnly);
QCOMPARE(int(file2.handle()), int(fileno(fp)));
QCOMPARE(int(file2.handle()), int(fileno(fp)));
QCOMPARE(int(file2.handle()), int(QT_FILENO(fp)));
QCOMPARE(int(file2.handle()), int(QT_FILENO(fp)));
fp.close();
//test round trip of adopted posix file handle

View File

@ -57,8 +57,10 @@
#if defined(Q_OS_WIN)
#include <QtCore/qt_windows.h>
#include <private/qwinregistry_p.h>
#define QT_UNLINK _unlink
#else
#include <unistd.h>
#define QT_UNLINK unlink
#endif
#if defined(Q_OS_DARWIN)
@ -1736,7 +1738,7 @@ void tst_QSettings::sync()
// Now "some other app" will change other.software.org.ini
QString userConfDir = settingsPath("__user__") + QDir::separator();
unlink((userConfDir + "other.software.org.ini").toLatin1());
QT_UNLINK((userConfDir + "other.software.org.ini").toLatin1());
rename((userConfDir + "software.org.ini").toLatin1(),
(userConfDir + "other.software.org.ini").toLatin1());