globalplatform
error.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005-2026, Karsten Ohme
3  * This file is part of GlobalPlatform.
4  *
5  * GlobalPlatform is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * GlobalPlatform is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with GlobalPlatform. If not, see <https://www.gnu.org/licenses/>.
17  *
18  * In addition, as a special exception, the copyright holders give
19  * permission to link the code of portions of this program with the
20  * OpenSSL library under certain conditions as described in each
21  * individual source file, and distribute linked combinations
22  * including the two.
23  * You must obey the GNU Lesser General Public License in all respects
24  * for all of the code used other than OpenSSL. If you modify
25  * file(s) with this exception, you may extend this exception to your
26  * version of the file(s), but you are not obligated to do so. If you
27  * do not wish to do so, delete this exception statement from your
28  * version.
29  */
30 
35 #ifndef OPGP_ERROR_H
36 #define OPGP_ERROR_H
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #include "unicode.h"
44 
45 #ifdef _WIN32
46 #define OPGP_ERROR_STATUS_SUCCESS ERROR_SUCCESS
47 #else
48 #define OPGP_ERROR_STATUS_SUCCESS 0
49 #endif
50 
51 #define OPGP_ERROR_STATUS_FAILURE 1
52 
53 #define ERROR_MESSAGE_LENGTH 256
54 
58 typedef struct {
61  TCHAR errorMessage[ERROR_MESSAGE_LENGTH+1];
63 
68 #define OPGP_ERROR_CHECK(status) status.errorStatus
69 
76 #define OPGP_ERROR_CREATE_ERROR(status, code, message) status.errorStatus = OPGP_ERROR_STATUS_FAILURE; \
77  status.errorCode = code; \
78  _tcsncpy(status.errorMessage, message, ERROR_MESSAGE_LENGTH); status.errorMessage[ERROR_MESSAGE_LENGTH] = _T('\0')
79 
84 #define OPGP_ERROR_CREATE_NO_ERROR(status) status.errorStatus = OPGP_ERROR_STATUS_SUCCESS; status.errorCode = 0; \
85  _tcsncpy(status.errorMessage, _T("Success"), ERROR_MESSAGE_LENGTH); status.errorMessage[ERROR_MESSAGE_LENGTH] = _T('\0')
86 
93 #define OPGP_ERROR_CREATE_NO_ERROR_WITH_CODE(status, code, message) status.errorStatus = OPGP_ERROR_STATUS_SUCCESS; \
94  status.errorCode = code; \
95  _tcsncpy(status.errorMessage, message, ERROR_MESSAGE_LENGTH); status.errorMessage[ERROR_MESSAGE_LENGTH] = _T('\0')
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 #endif
Definition: error.h:58
LONG errorStatus
Identifies, if an error occurred. If no error occurred OPGP_ERROR_STATUS_SUCCESS must be set....
Definition: error.h:59
DWORD errorCode
The error code represented as an unsigned 32-bit value.
Definition: error.h:60
long LONG
A long value.
Definition: types.h:69
unsigned long DWORD
A Microsoft/Muscle DWORD definition.
Definition: types.h:68