qsystemerror.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qsystemerror.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <qglobal.h>-
41#include "qsystemerror_p.h"-
42#if !defined(Q_OS_WINCE)-
43# include <errno.h>-
44# if defined(Q_CC_MSVC)-
45# include <crtdbg.h>-
46# endif-
47#else-
48# if (_WIN32_WCE >= 0x700)-
49# include <errno.h>-
50# endif-
51#endif-
52#ifdef Q_OS_WIN-
53# include <qt_windows.h>-
54#endif-
55-
56QT_BEGIN_NAMESPACE-
57-
58#if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \-
59 defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L-
60namespace {-
61 // There are two incompatible versions of strerror_r:-
62 // a) the XSI/POSIX.1 version, which returns an int,-
63 // indicating success or not-
64 // b) the GNU version, which returns a char*, which may or may not-
65 // be the beginning of the buffer we used-
66 // The GNU libc manpage for strerror_r says you should use the XSI-
67 // version in portable code. However, it's impossible to do that if-
68 // _GNU_SOURCE is defined so we use C++ overloading to decide what to do-
69 // depending on the return type-
70 static inline Q_DECL_UNUSED QString fromstrerror_helper(int, const QByteArray &buf)-
71 {-
72 return QString::fromLocal8Bit(buf);-
73 }-
74 static inline Q_DECL_UNUSED QString fromstrerror_helper(const char *str, const QByteArray &)-
75 {-
76 return QString::fromLocal8Bit(str);-
77 }-
78}-
79#endif-
80-
81#ifdef Q_OS_WIN-
82static QString windowsErrorString(int errorCode)-
83{-
84 QString ret;-
85#ifndef Q_OS_WINRT-
86 wchar_t *string = 0;-
87 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,-
88 NULL,-
89 errorCode,-
90 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),-
91 (LPWSTR)&string,-
92 0,-
93 NULL);-
94 ret = QString::fromWCharArray(string);-
95 LocalFree((HLOCAL)string);-
96#else-
97 wchar_t errorString[1024];-
98 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,-
99 NULL,-
100 errorCode,-
101 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),-
102 (LPWSTR)&errorString,-
103 sizeof(errorString)/sizeof(wchar_t),-
104 NULL);-
105 ret = QString::fromWCharArray(errorString);-
106#endif // Q_OS_WINRT-
107-
108 if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)-
109 ret = QString::fromLatin1("The specified module could not be found.");-
110 return ret;-
111}-
112#endif-
113-
114static QString standardLibraryErrorString(int errorCode)-
115{-
116 const char *s = 0;-
117 QString ret;-
118 switch (errorCode) {-
119 case 0:
never executed: case 0:
0
120 break;
never executed: break;
0
121 case EACCES:
executed 10 times by 4 tests: case 13:
Executed by:
  • tst_QDir
  • tst_QFile
  • tst_QSaveFile
  • tst_QTemporaryFile
10
122 s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");-
123 break;
executed 10 times by 4 tests: break;
Executed by:
  • tst_QDir
  • tst_QFile
  • tst_QSaveFile
  • tst_QTemporaryFile
10
124 case EMFILE:
never executed: case 24:
0
125 s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");-
126 break;
never executed: break;
0
127 case ENOENT:
executed 599 times by 22 tests: case 2:
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTemporaryFile
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
599
128 s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");-
129 break;
executed 599 times by 22 tests: break;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTemporaryFile
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
599
130 case ENOSPC:
never executed: case 28:
0
131 s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");-
132 break;
never executed: break;
0
133 default: {
executed 107 times by 3 tests: default:
Executed by:
  • tst_QFile
  • tst_QImageReader
  • tst_QLocalSocket
107
134 #ifdef Q_OS_WINCE-
135 ret = windowsErrorString(errorCode);-
136 #else-
137 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)-
138 QByteArray buf(1024, '\0');-
139 ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);-
140 #else-
141 ret = QString::fromLocal8Bit(strerror(errorCode));-
142 #endif-
143 #endif-
144 break; }
executed 107 times by 3 tests: break;
Executed by:
  • tst_QFile
  • tst_QImageReader
  • tst_QLocalSocket
107
145 }-
146 if (s) {
sDescription
TRUEevaluated 609 times by 22 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTemporaryFile
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
FALSEevaluated 107 times by 3 tests
Evaluated by:
  • tst_QFile
  • tst_QImageReader
  • tst_QLocalSocket
107-609
147 // ######## this breaks moc build currently-
148 // ret = QCoreApplication::translate("QIODevice", s);-
149 ret = QString::fromLatin1(s);-
150 }
executed 609 times by 22 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTemporaryFile
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
609
151 return ret.trimmed();
executed 716 times by 23 tests: return ret.trimmed();
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTemporaryFile
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
716
152}-
153-
154QString QSystemError::toString() const-
155{-
156 switch(errorScope) {-
157 case NativeError:
executed 15 times by 3 tests: case NativeError:
Executed by:
  • tst_QFileSystemWatcher
  • tst_QSaveFile
  • tst_QTemporaryFile
15
158#if defined (Q_OS_WIN)-
159 return windowsErrorString(errorCode);-
160#else-
161 //unix: fall through as native and standard library are the same-
162#endif-
163 case StandardLibraryError:
executed 701 times by 23 tests: case StandardLibraryError:
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTemporaryFile
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
701
164 return standardLibraryErrorString(errorCode);
executed 716 times by 23 tests: return standardLibraryErrorString(errorCode);
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTemporaryFile
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
716
165 default:
never executed: default:
0
166 qWarning("invalid error scope");-
167 //fall through-
168 case NoError:
code before this statement never executed: case NoError:
never executed: case NoError:
0
169 return QLatin1String("No error");
never executed: return QLatin1String("No error");
0
170 }-
171}-
172-
173QT_END_NAMESPACE-
174-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9