Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
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 Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include <qglobal.h> | - |
43 | #include "qsystemerror_p.h" | - |
44 | #if !defined(Q_OS_WINCE) | - |
45 | # include <errno.h> | - |
46 | # if defined(Q_CC_MSVC) | - |
47 | # include <crtdbg.h> | - |
48 | # endif | - |
49 | #else | - |
50 | # if (_WIN32_WCE >= 0x700) | - |
51 | # include <errno.h> | - |
52 | # endif | - |
53 | #endif | - |
54 | #ifdef Q_OS_WIN | - |
55 | # include <qt_windows.h> | - |
56 | #endif | - |
57 | | - |
58 | QT_BEGIN_NAMESPACE | - |
59 | | - |
60 | #if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \ | - |
61 | defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L | - |
62 | namespace { | - |
63 | // There are two incompatible versions of strerror_r: | - |
64 | // a) the XSI/POSIX.1 version, which returns an int, | - |
65 | // indicating success or not | - |
66 | // b) the GNU version, which returns a char*, which may or may not | - |
67 | // be the beginning of the buffer we used | - |
68 | // The GNU libc manpage for strerror_r says you should use the XSI | - |
69 | // version in portable code. However, it's impossible to do that if | - |
70 | // _GNU_SOURCE is defined so we use C++ overloading to decide what to do | - |
71 | // depending on the return type | - |
72 | static inline QString fromstrerror_helper(int, const QByteArray &buf) | - |
73 | { | - |
74 | return QString::fromLocal8Bit(buf); never executed: return QString::fromLocal8Bit(buf); | 0 |
75 | } | - |
76 | static inline QString fromstrerror_helper(const char *str, const QByteArray &) | - |
77 | { | - |
78 | return QString::fromLocal8Bit(str); executed: return QString::fromLocal8Bit(str); Execution Count:119 | 119 |
79 | } | - |
80 | } | - |
81 | #endif | - |
82 | | - |
83 | #ifdef Q_OS_WIN | - |
84 | static QString windowsErrorString(int errorCode) | - |
85 | { | - |
86 | QString ret; | - |
87 | wchar_t *string = 0; | - |
88 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, | - |
89 | NULL, | - |
90 | errorCode, | - |
91 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | - |
92 | (LPWSTR)&string, | - |
93 | 0, | - |
94 | NULL); | - |
95 | ret = QString::fromWCharArray(string); | - |
96 | LocalFree((HLOCAL)string); | - |
97 | | - |
98 | if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND) | - |
99 | ret = QString::fromLatin1("The specified module could not be found."); | - |
100 | return ret; | - |
101 | } | - |
102 | #endif | - |
103 | | - |
104 | static QString standardLibraryErrorString(int errorCode) | - |
105 | { | - |
106 | const char *s = 0; executed (the execution status of this line is deduced): const char *s = 0; | - |
107 | QString ret; executed (the execution status of this line is deduced): QString ret; | - |
108 | switch (errorCode) { | - |
109 | case 0: | - |
110 | break; | 0 |
111 | case EACCES: | - |
112 | s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied"); executed (the execution status of this line is deduced): s = "Permission denied"; | - |
113 | break; executed: break; Execution Count:3 | 3 |
114 | case EMFILE: | - |
115 | s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files"); never executed (the execution status of this line is deduced): s = "Too many open files"; | - |
116 | break; | 0 |
117 | case ENOENT: | - |
118 | s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory"); executed (the execution status of this line is deduced): s = "No such file or directory"; | - |
119 | break; executed: break; Execution Count:605 | 605 |
120 | case ENOSPC: | - |
121 | s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device"); never executed (the execution status of this line is deduced): s = "No space left on device"; | - |
122 | break; | 0 |
123 | default: { | - |
124 | #ifdef Q_OS_WINCE | - |
125 | ret = windowsErrorString(errorCode); | - |
126 | #else | - |
127 | #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) | - |
128 | QByteArray buf(1024, '\0'); executed (the execution status of this line is deduced): QByteArray buf(1024, '\0'); | - |
129 | ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf); executed (the execution status of this line is deduced): ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf); | - |
130 | #else | - |
131 | ret = QString::fromLocal8Bit(strerror(errorCode)); | - |
132 | #endif | - |
133 | #endif | - |
134 | break; } executed: break; Execution Count:119 | 119 |
135 | } | - |
136 | if (s) { evaluated: s yes Evaluation Count:608 | yes Evaluation Count:119 |
| 119-608 |
137 | // ######## this breaks moc build currently | - |
138 | // ret = QCoreApplication::translate("QIODevice", s); | - |
139 | ret = QString::fromLatin1(s); executed (the execution status of this line is deduced): ret = QString::fromLatin1(s); | - |
140 | } executed: } Execution Count:608 | 608 |
141 | return ret.trimmed(); executed: return ret.trimmed(); Execution Count:727 | 727 |
142 | } | - |
143 | | - |
144 | QString QSystemError::toString() | - |
145 | { | - |
146 | switch(errorScope) { | - |
147 | case NativeError: | - |
148 | #if defined (Q_OS_WIN) | - |
149 | return windowsErrorString(errorCode); | - |
150 | #else | - |
151 | //unix: fall through as native and standard library are the same | - |
152 | #endif | - |
153 | case StandardLibraryError: | - |
154 | return standardLibraryErrorString(errorCode); executed: return standardLibraryErrorString(errorCode); Execution Count:727 | 727 |
155 | default: | - |
156 | qWarning("invalid error scope"); never executed (the execution status of this line is deduced): QMessageLogger("kernel/qsystemerror.cpp", 156, __PRETTY_FUNCTION__).warning("invalid error scope"); | - |
157 | //fall through | - |
158 | case NoError: | - |
159 | return QLatin1String("No error"); never executed: return QLatin1String("No error"); | 0 |
160 | } | - |
161 | } | 0 |
162 | | - |
163 | QT_END_NAMESPACE | - |
164 | | - |
165 | | - |
| | |