From f3205a49498d3084f46bc2c2abcd085c8436553b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Jun 2017 21:18:04 -0700 Subject: Merge qt_error_string and QSystemError This removes a lot of duplicated code that existed in both qglobal.cpp and qsystemerror.cpp, including the hack to get the correct strerror_r signature. This removes the incorrect use of EACCES, EMFILE, ENOENT, and ENOSPC from qt_error_string on Windows. qt_error_string is supposed to be used only with Win32 error codes from GetLastError(), despite there being a lot of uses in cross-platform and even Windows-specific code that pass errno constants. It may or may not work: that depends on whether the constants happen to match. ENOENT matches ERROR_FILE_NOT_FOUND and one could argue that ENOSPC matching ERROR_OUT_OF_PAPER is acceptable, but EMFILE isn't the same as ERROR_BAD_LENGTH nor is EACCES, ERROR_INVALID_DATA. Change-Id: I1eba2b016de74620bfc8fffd14cccb7f77f4b510 Reviewed-by: Friedemann Kleint Reviewed-by: Kai Koehne Reviewed-by: Thiago Macieira --- src/corelib/kernel/qsystemerror_p.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/corelib/kernel/qsystemerror_p.h') diff --git a/src/corelib/kernel/qsystemerror_p.h b/src/corelib/kernel/qsystemerror_p.h index 440b763149..1d8c253f53 100644 --- a/src/corelib/kernel/qsystemerror_p.h +++ b/src/corelib/kernel/qsystemerror_p.h @@ -69,10 +69,16 @@ public: inline QSystemError(int error, ErrorScope scope); inline QSystemError(); - QString toString() const; + inline QString toString() const; inline ErrorScope scope() const; inline int error() const; + static QString string(ErrorScope errorScope, int errorCode); + static QString stdString(int errorCode = -1); +#ifdef Q_OS_WIN + static QString windowsString(int errorCode = -1); +#endif + //data members int errorCode; ErrorScope errorScope; @@ -90,6 +96,11 @@ QSystemError::QSystemError() } +QString QSystemError::toString() const +{ + return string(errorScope, errorCode); +} + QSystemError::ErrorScope QSystemError::scope() const { return errorScope; @@ -100,7 +111,6 @@ int QSystemError::error() const return errorCode; } - QT_END_NAMESPACE #endif // QSYSTEMERROR_P_H -- cgit v1.2.3