summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2011-03-28 11:42:58 (GMT)
committerJoão Abecasis <joao.abecasis@nokia.com>2011-04-04 11:22:49 (GMT)
commit8f5dbf0ace53daf0b2b4d48f2c5151000f0d5720 (patch)
treea8f8900b1a00ed004901542c97afa9f3872ed925 /src
parent2c3d675b97c52ad925891de16d2ea9dcfa9fae4c (diff)
downloadQt-8f5dbf0ace53daf0b2b4d48f2c5151000f0d5720.zip
Qt-8f5dbf0ace53daf0b2b4d48f2c5151000f0d5720.tar.gz
Qt-8f5dbf0ace53daf0b2b4d48f2c5151000f0d5720.tar.bz2
Adding comments; variable scoping
There should be no semantic differences, otherwise. Reviewed-by: Harald Fernengel Reviewed-by: Robin Burchell
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp52
1 files changed, 30 insertions, 22 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index a9bed8b..939ea34 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -102,11 +102,6 @@ QT_BEGIN_NAMESPACE
static int _gettemp(char *path, int slen)
{
char *start, *trv, *suffp;
-#if defined(Q_OS_WIN)
- int pid;
-#else
- pid_t pid;
-#endif
for (trv = path; *trv; ++trv)
;
@@ -117,32 +112,43 @@ static int _gettemp(char *path, int slen)
errno = EINVAL;
return -1;
}
+
+ // Initialize placeholder with random chars + PID.
+ {
+#if defined(Q_OS_WIN)
+ int pid;
+#else
+ pid_t pid;
+#endif
+
#if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400
- pid = _getpid();
+ pid = _getpid();
#elif defined(Q_OS_VXWORKS)
- pid = (pid_t) taskIdCurrent;
+ pid = (pid_t) taskIdCurrent;
#else
- pid = getpid();
+ pid = getpid();
#endif
- while (trv >= path && *trv == 'X' && pid != 0) {
- *trv-- = (pid % 10) + '0';
- pid /= 10;
- }
+ while (trv >= path && *trv == 'X' && pid != 0) {
+ *trv-- = (pid % 10) + '0';
+ pid /= 10;
+ }
- while (trv >= path && *trv == 'X') {
- char c;
+ while (trv >= path && *trv == 'X') {
+ char c;
- // CHANGE arc4random() -> random()
- pid = (qrand() & 0xffff) % (26+26);
- if (pid < 26)
- c = pid + 'A';
- else
- c = (pid - 26) + 'a';
- *trv-- = c;
+ // CHANGE arc4random() -> random()
+ int pid = (qrand() & 0xffff) % (26+26);
+ if (pid < 26)
+ c = pid + 'A';
+ else
+ c = (pid - 26) + 'a';
+ *trv-- = c;
+ }
+ start = trv + 1;
}
- start = trv + 1;
for (;;) {
+ // Atomically create file and obtain handle
#ifndef Q_OS_WIN
{
int fd = QT_OPEN(path, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE, 0600);
@@ -158,6 +164,8 @@ static int _gettemp(char *path, int slen)
/* tricky little algorwwithm for backward compatibility */
for (trv = start;;) {
+ // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
+ // String progression: "ZZaiC" => "aabiC"
if (!*trv)
return -1;
if (*trv == 'Z') {