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