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

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