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