globalplatform
error.h
Go to the documentation of this file.
1 /* Copyright (c) 2009, Karsten Ohme
2  * This file is part of GlobalPlatform.
3  *
4  * GlobalPlatform is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * GlobalPlatform is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with GlobalPlatform. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
22 #ifndef OPGP_ERROR_H
23 #define OPGP_ERROR_H
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
30 #include "unicode.h"
31 
32 #ifdef _WIN32
33 #define OPGP_ERROR_STATUS_SUCCESS ERROR_SUCCESS
34 #else
35 #define OPGP_ERROR_STATUS_SUCCESS 0
36 #endif
37 
38 #define OPGP_ERROR_STATUS_FAILURE 1
39 
40 #define ERROR_MESSAGE_LENGTH 256
41 
45 typedef struct {
48  TCHAR errorMessage[ERROR_MESSAGE_LENGTH+1];
50 
55 #define OPGP_ERROR_CHECK(status) status.errorStatus
56 
63 #define OPGP_ERROR_CREATE_ERROR(status, code, message) status.errorStatus = OPGP_ERROR_STATUS_FAILURE; \
64  status.errorCode = code; \
65  _tcsncpy(status.errorMessage, message, ERROR_MESSAGE_LENGTH); status.errorMessage[ERROR_MESSAGE_LENGTH] = _T('\0')
66 
71 #define OPGP_ERROR_CREATE_NO_ERROR(status) status.errorStatus = OPGP_ERROR_STATUS_SUCCESS; status.errorCode = 0; \
72  _tcsncpy(status.errorMessage, _T("Success"), ERROR_MESSAGE_LENGTH); status.errorMessage[ERROR_MESSAGE_LENGTH] = _T('\0')
73 
80 #define OPGP_ERROR_CREATE_NO_ERROR_WITH_CODE(status, code, message) status.errorStatus = OPGP_ERROR_STATUS_SUCCESS; \
81  status.errorCode = code; \
82  _tcsncpy(status.errorMessage, message, ERROR_MESSAGE_LENGTH); status.errorMessage[ERROR_MESSAGE_LENGTH] = _T('\0')
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 #endif
88 
OPGP_ERROR_STATUS::errorCode
LONG errorCode
The error code.
Definition: error.h:47
OPGP_ERROR_STATUS::errorStatus
LONG errorStatus
Identifies, if an error occurred. If no error occurred OPGP_ERROR_STATUS_SUCCESS must be set....
Definition: error.h:46
LONG
long LONG
A long value.
Definition: types.h:53
OPGP_ERROR_STATUS
Definition: error.h:45
unicode.h