corelib/io: use qUtf16Printable(), %ls, qErrnoWarning()

... instead of qPrintable(), %s, explicit qt_error_string().

Saves temporary QByteArray creation, and 540b in text size on
optimized Linux AMD64 GCC 9.1 builds.

Change-Id: Id4e861683cf05a92faf51e4a9de9eb1dec4fc84a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
 
 
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2019-05-29 17:54:38 +02:00
parent b5e0bb9152
commit 9322ee7ace
6 changed files with 35 additions and 34 deletions

View File

@ -169,7 +169,7 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys()
if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) {
qt_safe_close(fd);
if (!QFile::remove(fileName))
qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName));
qWarning("QLockFile: Could not remove our own lock file %ls.", qUtf16Printable(fileName));
return QLockFile::UnknownError; // partition full
}

View File

@ -202,8 +202,7 @@ static int qt_create_pipe(int *pipe)
qt_safe_close(pipe[1]);
int pipe_ret = qt_safe_pipe(pipe);
if (pipe_ret != 0) {
qWarning("QProcessPrivate::createPipe: Cannot create pipe %p: %s",
pipe, qPrintable(qt_error_string(errno)));
qErrnoWarning("QProcessPrivate::createPipe: Cannot create pipe %p", pipe);
}
return pipe_ret;
}
@ -473,7 +472,7 @@ void QProcessPrivate::startProcess()
if (forkfd == -1) {
// Cleanup, report error and return
#if defined (QPROCESS_DEBUG)
qDebug("fork failed: %s", qPrintable(qt_error_string(lastForkErrno)));
qDebug("fork failed: %ls", qUtf16Printable(qt_error_string(lastForkErrno)));
#endif
q->setProcessState(QProcess::NotRunning);
setErrorAndEmit(QProcess::FailedToStart,
@ -652,7 +651,7 @@ bool QProcessPrivate::writeToStdin()
qDebug("QProcessPrivate::writeToStdin(), write(%p \"%s\", %lld) == %lld",
data, qt_prettyDebug(data, bytesToWrite, 16).constData(), bytesToWrite, written);
if (written == -1)
qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qPrintable(qt_error_string(errno)));
qDebug("QProcessPrivate::writeToStdin(), failed to write (%ls)", qUtf16Printable(qt_error_string(errno)));
#endif
if (written == -1) {
// If the O_NONBLOCK flag is set and If some data can be written without blocking

View File

@ -193,7 +193,7 @@ bool QSaveFile::open(OpenMode mode)
{
Q_D(QSaveFile);
if (isOpen()) {
qWarning("QSaveFile::open: File (%s) already open", qPrintable(fileName()));
qWarning("QSaveFile::open: File (%ls) already open", qUtf16Printable(fileName()));
return false;
}
unsetError();
@ -326,7 +326,7 @@ bool QSaveFile::commit()
return false;
if (!isOpen()) {
qWarning("QSaveFile::commit: File (%s) is not open", qPrintable(fileName()));
qWarning("QSaveFile::commit: File (%ls) is not open", qUtf16Printable(fileName()));
return false;
}
QFileDevice::close(); // calls flush()

View File

@ -166,8 +166,8 @@ static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSub
if (res == ERROR_SUCCESS)
return resultHandle;
//qWarning("QSettings: Failed to create subkey \"%s\": %s",
// qPrintable(rSubKey), qPrintable(qt_error_string(int(res))));
//qErrnoWarning(int(res), "QSettings: Failed to create subkey \"%ls\"",
// qUtf16Printable(rSubKey));
return 0;
}
@ -207,7 +207,7 @@ static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildS
&numKeys, &maxKeySize, 0, 0, 0);
if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegQueryInfoKey() failed: %s", qPrintable(qt_error_string(int(res))));
qErrnoWarning(int(res), "QSettings: RegQueryInfoKey() failed");
return result;
}
@ -241,7 +241,7 @@ static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildS
item = QString::fromWCharArray((const wchar_t *)buff.constData(), l);
if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegEnumValue failed: %s", qPrintable(qt_error_string(int(res))));
qErrnoWarning(int(res), "QSettings: RegEnumValue failed");
continue;
}
if (item.isEmpty())
@ -295,8 +295,8 @@ static void deleteChildGroups(HKEY parentHandle, REGSAM access = 0)
// delete group itself
LONG res = RegDeleteKey(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16()));
if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegDeleteKey failed on subkey \"%s\": %s",
qPrintable(group), qPrintable(qt_error_string(int(res))));
qErrnoWarning(int(res), "QSettings: RegDeleteKey failed on subkey \"%ls\"",
qUtf16Printable(group));
return;
}
}
@ -596,8 +596,8 @@ QWinSettingsPrivate::~QWinSettingsPrivate()
QString emptyKey;
DWORD res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
if (res != ERROR_SUCCESS) {
qWarning("QSettings: Failed to delete key \"%s\": %s",
qPrintable(regList.at(0).key()), qPrintable(qt_error_string(int(res))));
qErrnoWarning(int(res), "QSettings: Failed to delete key \"%ls\"",
qUtf16Printable(regList.constFirst().key()));
}
}
@ -633,16 +633,16 @@ void QWinSettingsPrivate::remove(const QString &uKey)
for (const QString &group : childKeys) {
LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s",
qPrintable(group), qPrintable(qt_error_string(int(res))));
qErrnoWarning(int(res), "QSettings: RegDeleteValue failed on subkey \"%ls\"",
qUtf16Printable(group));
}
}
} else {
res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));
if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegDeleteKey failed on key \"%s\": %s",
qPrintable(rKey), qPrintable(qt_error_string(int(res))));
qErrnoWarning(int(res), "QSettings: RegDeleteKey failed on key \"%ls\"",
qUtf16Printable(rKey));
}
}
RegCloseKey(handle);
@ -739,8 +739,8 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value)
if (res == ERROR_SUCCESS) {
deleteWriteHandleOnExit = false;
} else {
qWarning("QSettings: failed to set subkey \"%s\": %s",
qPrintable(rKey), qPrintable(qt_error_string(int(res))));
qErrnoWarning(int(res), "QSettings: failed to set subkey \"%ls\"",
qUtf16Printable(rKey));
setStatus(QSettings::AccessError);
}

View File

@ -130,29 +130,31 @@ QString QStandardPaths::writableLocation(StandardLocation type)
fileInfo.setFile(xdgRuntimeDir);
if (!fileInfo.isDir()) {
if (!QDir().mkdir(xdgRuntimeDir)) {
qWarning("QStandardPaths: error creating runtime directory %s: %s", qPrintable(xdgRuntimeDir), qPrintable(qt_error_string(errno)));
qErrnoWarning("QStandardPaths: error creating runtime directory %ls",
qUtf16Printable(xdgRuntimeDir));
return QString();
}
}
#ifndef Q_OS_WASM
qWarning("QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '%s'", qPrintable(xdgRuntimeDir));
qWarning("QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '%ls'", qUtf16Printable(xdgRuntimeDir));
#endif
} else {
fileInfo.setFile(xdgRuntimeDir);
if (!fileInfo.exists()) {
qWarning("QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '%s', "
"please create it with 0700 permissions.", qPrintable(xdgRuntimeDir));
qWarning("QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '%ls', "
"please create it with 0700 permissions.", qUtf16Printable(xdgRuntimeDir));
return QString();
}
if (!fileInfo.isDir()) {
qWarning("QStandardPaths: XDG_RUNTIME_DIR points to '%s' which is not a directory",
qPrintable(xdgRuntimeDir));
qWarning("QStandardPaths: XDG_RUNTIME_DIR points to '%ls' which is not a directory",
qUtf16Printable(xdgRuntimeDir));
return QString();
}
}
// "The directory MUST be owned by the user"
if (fileInfo.ownerId() != myUid) {
qWarning("QStandardPaths: wrong ownership on runtime directory %s, %d instead of %d", qPrintable(xdgRuntimeDir),
qWarning("QStandardPaths: wrong ownership on runtime directory %ls, %d instead of %d",
qUtf16Printable(xdgRuntimeDir),
fileInfo.ownerId(), myUid);
return QString();
}
@ -163,8 +165,8 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (fileInfo.permissions() != wantedPerms) {
QFile file(xdgRuntimeDir);
if (!file.setPermissions(wantedPerms)) {
qWarning("QStandardPaths: could not set correct permissions on runtime directory %s: %s",
qPrintable(xdgRuntimeDir), qPrintable(file.errorString()));
qWarning("QStandardPaths: could not set correct permissions on runtime directory %ls: %ls",
qUtf16Printable(xdgRuntimeDir), qUtf16Printable(file.errorString()));
return QString();
}
}

View File

@ -3266,10 +3266,10 @@ QUrl QUrl::resolved(const QUrl &relative) const
removeDotsFromPath(&t.d->path);
#if defined(QURL_DEBUG)
qDebug("QUrl(\"%s\").resolved(\"%s\") = \"%s\"",
qPrintable(url()),
qPrintable(relative.url()),
qPrintable(t.url()));
qDebug("QUrl(\"%ls\").resolved(\"%ls\") = \"%ls\"",
qUtf16Printable(url()),
qUtf16Printable(relative.url()),
qUtf16Printable(t.url()));
#endif
return t;
}