replace typedefs with the actual type in createFileFromTemplate() function

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2020-01-05 17:08:12 +00:00
parent a072d774fe
commit 7345cfb219

View file

@ -51,10 +51,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
typedef char Char;
typedef char Latin1Char;
typedef int NativeFileHandle;
/* /*
* Copyright (c) 1987, 1993 * Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
@ -96,7 +92,7 @@ typedef int NativeFileHandle;
handle otherwise. In both cases, the string in \a path will be changed and handle otherwise. In both cases, the string in \a path will be changed and
contain the generated path name. contain the generated path name.
*/ */
static bool createFileFromTemplate(NativeFileHandle &file, static bool createFileFromTemplate(int &file,
QFileSystemEntry::NativePath &path, size_t pos, size_t length, QFileSystemEntry::NativePath &path, size_t pos, size_t length,
QSystemError &error) QSystemError &error)
{ {
@ -104,17 +100,17 @@ static bool createFileFromTemplate(NativeFileHandle &file,
Q_ASSERT(pos < size_t(path.length())); Q_ASSERT(pos < size_t(path.length()));
Q_ASSERT(length <= size_t(path.length()) - pos); Q_ASSERT(length <= size_t(path.length()) - pos);
Char *const placeholderStart = (Char *)path.data() + pos; char *const placeholderStart = path.data() + pos;
Char *const placeholderEnd = placeholderStart + length; char *const placeholderEnd = placeholderStart + length;
// Initialize placeholder with random chars + PID. // Initialize placeholder with random chars + PID.
{ {
Char *rIter = placeholderEnd; char *rIter = placeholderEnd;
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
quint64 pid = quint64(QCoreApplication::applicationPid()); quint64 pid = quint64(QCoreApplication::applicationPid());
do { do {
*--rIter = Latin1Char((pid % 10) + '0'); *--rIter = char((pid % 10) + '0');
pid /= 10; pid /= 10;
} while (rIter != placeholderStart && pid != 0); } while (rIter != placeholderStart && pid != 0);
#endif #endif
@ -122,9 +118,9 @@ static bool createFileFromTemplate(NativeFileHandle &file,
while (rIter != placeholderStart) { while (rIter != placeholderStart) {
char ch = char((qrand() & 0xffff) % (26 + 26)); char ch = char((qrand() & 0xffff) % (26 + 26));
if (ch < 26) if (ch < 26)
*--rIter = Latin1Char(ch + 'A'); *--rIter = char(ch + 'A');
else else
*--rIter = Latin1Char(ch - 26 + 'a'); *--rIter = char(ch - 26 + 'a');
} }
} }
@ -143,13 +139,13 @@ static bool createFileFromTemplate(NativeFileHandle &file,
} }
/* tricky little algorithm for backward compatibility */ /* tricky little algorithm for backward compatibility */
for (Char *iter = placeholderStart;;) { for (char *iter = placeholderStart;;) {
// Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z' // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
// String progression: "ZZaiC" => "aabiC" // String progression: "ZZaiC" => "aabiC"
switch (char(*iter)) { switch (*iter) {
case 'Z': case 'Z':
// Rollover, advance next character // Rollover, advance next character
*iter = Latin1Char('a'); *iter = 'a';
if (++iter == placeholderEnd) { if (++iter == placeholderEnd) {
// Out of alternatives. Return file exists error, previously set. // Out of alternatives. Return file exists error, previously set.
error = QSystemError(err, QSystemError::NativeError); error = QSystemError(err, QSystemError::NativeError);
@ -160,12 +156,12 @@ static bool createFileFromTemplate(NativeFileHandle &file,
case '0': case '1': case '2': case '3': case '4': case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '5': case '6': case '7': case '8': case '9':
*iter = Latin1Char('a'); *iter = 'a';
break; break;
case 'z': case 'z':
// increment 'z' to 'A' // increment 'z' to 'A'
*iter = Latin1Char('A'); *iter = 'A';
break; break;
default: default:
@ -284,7 +280,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
while (phPos != 0) { while (phPos != 0) {
--phPos; --phPos;
if (filename[phPos] == Latin1Char('X')) { if (filename[phPos] == 'X') {
++phLength; ++phLength;
continue; continue;
} }
@ -301,9 +297,8 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
Q_ASSERT(phLength >= 6); Q_ASSERT(phLength >= 6);
QSystemError error; QSystemError error;
NativeFileHandle &file = d->fd;
if (!createFileFromTemplate(file, filename, phPos, phLength, error)) { if (!createFileFromTemplate(d->fd, filename, phPos, phLength, error)) {
setError(QFile::OpenError, error.toString()); setError(QFile::OpenError, error.toString());
return false; return false;
} }