1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
3 |
|
---|
4 | #ifndef CRT_ABSTRACTIONS_H
|
---|
5 | #define CRT_ABSTRACTIONS_H
|
---|
6 |
|
---|
7 | #ifdef __cplusplus
|
---|
8 | #include <cstdint>
|
---|
9 | #include <cstdio>
|
---|
10 | #include <cstring>
|
---|
11 | #include <cerrno>
|
---|
12 | #include <cmath>
|
---|
13 | #else // __cplusplus
|
---|
14 | #include <stdint.h>
|
---|
15 | #include <stdio.h>
|
---|
16 | #include <string.h>
|
---|
17 | #include <errno.h>
|
---|
18 | #endif // __cplusplus
|
---|
19 |
|
---|
20 | #include "umock_c/umock_c_prod.h"
|
---|
21 |
|
---|
22 | #ifdef _MSC_VER
|
---|
23 |
|
---|
24 | #ifdef QUARKGALILEO
|
---|
25 | #define HAS_STDBOOL
|
---|
26 | #ifdef __cplusplus
|
---|
27 | typedef bool _Bool;
|
---|
28 | #else
|
---|
29 | /*galileo apparently has _Bool and bool as built in types*/
|
---|
30 | #endif
|
---|
31 | #endif // QUARKGALILEO
|
---|
32 |
|
---|
33 | #define HAS_STDBOOL
|
---|
34 | #ifdef __cplusplus
|
---|
35 | /*because C++ doesn't do anything about _Bool... */
|
---|
36 | #define _Bool bool
|
---|
37 | #else // __cplusplus
|
---|
38 | #include <stdbool.h>
|
---|
39 | #endif // __cplusplus
|
---|
40 |
|
---|
41 | #else // _MSC_VER
|
---|
42 |
|
---|
43 | #if defined __STDC_VERSION__
|
---|
44 | #if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L) || (__STDC_VERSION__ == 201710L))
|
---|
45 | /*C99, C11 (including GNU 4.6) or C18 compiler */
|
---|
46 | #define HAS_STDBOOL
|
---|
47 | #include <stdbool.h>
|
---|
48 | #endif // ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L) || (__STDC_VERSION__ == 201710L))
|
---|
49 | #endif // __STDC_VERSION__
|
---|
50 | #endif // _MSC_VER
|
---|
51 |
|
---|
52 | #ifdef __cplusplus
|
---|
53 | extern "C" {
|
---|
54 | #endif // __cplusplus
|
---|
55 |
|
---|
56 | #ifndef HAS_STDBOOL
|
---|
57 | #ifdef __cplusplus
|
---|
58 | #define _Bool bool
|
---|
59 | #else // __cplusplus
|
---|
60 | typedef unsigned char _Bool;
|
---|
61 | typedef unsigned char bool;
|
---|
62 | #define false 0
|
---|
63 | #define true 1
|
---|
64 | #endif // __cplusplus
|
---|
65 | #endif // HAS_STDBOOL
|
---|
66 |
|
---|
67 |
|
---|
68 | /* Codes_SRS_CRT_ABSTRACTIONS_99_001:[The module shall not redefine the secure functions implemented by Microsoft CRT.] */
|
---|
69 | /* Codes_SRS_CRT_ABSTRACTIONS_99_040 : [The module shall still compile when building on a Microsoft platform.] */
|
---|
70 | /* Codes_SRS_CRT_ABSTRACTIONS_99_002: [CRTAbstractions module shall expose the following API]*/
|
---|
71 | #if defined (_MSC_VER) || defined (MINGW_HAS_SECURE_API)
|
---|
72 | #else // _MSC_VER || MINGW_HAS_SECURE_API
|
---|
73 |
|
---|
74 | /* Adding definitions from errno.h & crtdefs.h */
|
---|
75 | #if !defined (_TRUNCATE)
|
---|
76 | #define _TRUNCATE ((size_t)-1)
|
---|
77 | #endif /* !defined (_TRUNCATE) */
|
---|
78 |
|
---|
79 | #if !defined STRUNCATE
|
---|
80 | #define STRUNCATE 80
|
---|
81 | #endif /* !defined (STRUNCATE) */
|
---|
82 |
|
---|
83 | int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src);
|
---|
84 | int strcat_s(char* dst, size_t dstSizeInBytes, const char* src);
|
---|
85 | int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount);
|
---|
86 | int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...);
|
---|
87 | #endif // _MSC_VER || MINGW_HAS_SECURE_API
|
---|
88 |
|
---|
89 | unsigned long long strtoull_s(const char* nptr, char** endPtr, int base);
|
---|
90 | float strtof_s(const char* nptr, char** endPtr);
|
---|
91 | long double strtold_s(const char* nptr, char** endPtr);
|
---|
92 |
|
---|
93 | #ifdef _MSC_VER
|
---|
94 | #define stricmp _stricmp
|
---|
95 | #endif // _MSC_VER
|
---|
96 |
|
---|
97 | MOCKABLE_FUNCTION(, int, mallocAndStrcpy_s, char**, destination, const char*, source);
|
---|
98 | MOCKABLE_FUNCTION(, int, unsignedIntToString, char*, destination, size_t, destinationSize, unsigned int, value);
|
---|
99 | MOCKABLE_FUNCTION(, int, size_tToString, char*, destination, size_t, destinationSize, size_t, value);
|
---|
100 | MOCKABLE_FUNCTION(, int, uint64_tToString, char*, destination, size_t, destinationSize, uint64_t, value);
|
---|
101 |
|
---|
102 | /*following logic shall define the TOUPPER and ISDIGIT, we do that because the SDK is not happy with some Arduino implementation of it.*/
|
---|
103 | #define TOUPPER(c) ((((c)>='a') && ((c)<='z'))?(c)-'a'+'A':c)
|
---|
104 | #define ISDIGIT(c) ((((c)>='0') && ((c)<='9'))?1:0)
|
---|
105 |
|
---|
106 | /*following logic shall define the ISNAN macro*/
|
---|
107 | /*if runing on Microsoft Visual C compiler, than ISNAN shall be _isnan*/
|
---|
108 | /*else if running on C99 or C11, ISNAN shall be isnan*/
|
---|
109 | /*else if running on C89 ... #error and inform user*/
|
---|
110 |
|
---|
111 | #ifdef _MSC_VER
|
---|
112 | #define ISNAN _isnan
|
---|
113 | #else // _MSC_VER
|
---|
114 | #if defined __STDC_VERSION__
|
---|
115 | #if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L) || (__STDC_VERSION__ == 201710L))
|
---|
116 | /*C99, C11 (including GNU 4.6) or C18 compiler */
|
---|
117 | #define ISNAN isnan
|
---|
118 | #else // ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L) || (__STDC_VERSION__ == 201710L))
|
---|
119 | #error update this file to contain the latest C standard.
|
---|
120 | #endif // ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L) || (__STDC_VERSION__ == 201710L))
|
---|
121 | #else // __STDC_VERSION__
|
---|
122 | #ifdef __cplusplus
|
---|
123 | /*C++ defines isnan... in C11*/
|
---|
124 | extern "C++" {
|
---|
125 | #define ISNAN std::isnan
|
---|
126 | }
|
---|
127 | #else // __cplusplus
|
---|
128 | #error unknown (or C89) compiler, provide ISNAN with the same meaning as isnan in C99 standard
|
---|
129 | #endif // __cplusplus
|
---|
130 |
|
---|
131 | #endif // __STDC_VERSION__
|
---|
132 | #endif // _MSC_VER
|
---|
133 |
|
---|
134 | #ifdef __cplusplus
|
---|
135 | }
|
---|
136 | #endif // __cplusplus
|
---|
137 |
|
---|
138 | #endif /* CRT_ABSTRACTIONS_H */
|
---|