Nigel Rantor / azure_c_shared_utility

Fork of azure_c_shared_utility by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers crt_abstractions.h Source File

crt_abstractions.h

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #ifndef CRT_ABSTRACTIONS_H
00005 #define CRT_ABSTRACTIONS_H
00006 
00007 #include "azure_c_shared_utility/umock_c_prod.h"
00008 
00009 #ifdef __cplusplus
00010 #include <cstdio>
00011 #include <cstring>
00012 #include <cerrno>
00013 #include <cmath>
00014 extern "C" {
00015 #else // __cplusplus
00016 #include <stdio.h>
00017 #include <string.h>
00018 #include <errno.h>
00019 #endif // __cplusplus
00020 
00021 #ifdef _MSC_VER
00022 
00023 #ifdef QUARKGALILEO
00024 #define HAS_STDBOOL
00025 #ifdef __cplusplus
00026 typedef bool _Bool;
00027 #else
00028 /*galileo apparently has _Bool and bool as built in types*/
00029 #endif
00030 #endif // QUARKGALILEO
00031 
00032 #ifndef _WIN32_WCE
00033 #define HAS_STDBOOL
00034 #ifdef __cplusplus
00035 #include <cstdbool>
00036 /*because C++ doesn't do anything about _Bool... */
00037 #define _Bool bool
00038 #else // __cplusplus
00039 #include <stdbool.h>
00040 #endif // __cplusplus
00041 #else // _WIN32_WCE
00042 /* WINCE does not support bool as C datatype */
00043 #define __bool_true_false_are_defined   1
00044 
00045 #define HAS_STDBOOL
00046 
00047 #define _Bool bool
00048 
00049 #ifdef __cplusplus
00050 #define _CSTDBOOL_
00051 #else // __cplusplus
00052 typedef unsigned char bool;
00053 
00054 #define false   0
00055 #define true    1
00056 #endif // __cplusplus
00057 #endif // _WIN32_WCE
00058 
00059 #else //  _MSC_VER
00060 
00061 #if defined __STDC_VERSION__
00062 #if ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00063 /*C99 compiler or C11*/
00064 #define HAS_STDBOOL
00065 #include <stdbool.h>
00066 #endif //  ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00067 #endif // __STDC_VERSION__
00068 #endif //  _MSC_VER
00069 
00070 #ifndef HAS_STDBOOL
00071 #ifdef __cplusplus
00072 #define _Bool bool
00073 #else // __cplusplus
00074 typedef unsigned char _Bool;
00075 typedef unsigned char bool;
00076 #define false 0
00077 #define true 1
00078 #endif // __cplusplus
00079 #endif // HAS_STDBOOL
00080 
00081 
00082 /* Codes_SRS_CRT_ABSTRACTIONS_99_001:[The module shall not redefine the secure functions implemented by Microsoft CRT.] */
00083 /* Codes_SRS_CRT_ABSTRACTIONS_99_040 : [The module shall still compile when building on a Microsoft platform.] */
00084 /* Codes_SRS_CRT_ABSTRACTIONS_99_002: [CRTAbstractions module shall expose the following API]*/
00085 #ifdef _MSC_VER
00086 #else // _MSC_VER
00087 #include "inttypes.h"
00088 
00089 /* Adding definitions from errno.h & crtdefs.h */
00090 #if !defined (_TRUNCATE)
00091 #define _TRUNCATE ((size_t)-1)
00092 #endif  /* !defined (_TRUNCATE) */
00093 
00094 #if !defined STRUNCATE
00095 #define STRUNCATE       80
00096 #endif  /* !defined (STRUNCATE) */
00097 
00098 extern int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src);
00099 extern int strcat_s(char* dst, size_t dstSizeInBytes, const char* src);
00100 extern int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount);
00101 extern int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...);
00102 #endif // _MSC_VER
00103 
00104 extern unsigned long long strtoull_s(const char* nptr, char** endPtr, int base);
00105 extern float strtof_s(const char* nptr, char** endPtr);
00106 extern long double strtold_s(const char* nptr, char** endPtr);
00107 
00108 #ifdef _MSC_VER
00109 #define stricmp _stricmp
00110 #endif // _MSC_VER
00111 
00112 MOCKABLE_FUNCTION(, int, mallocAndStrcpy_s, char**, destination, const char*, source);
00113 MOCKABLE_FUNCTION(, int, unsignedIntToString, char*, destination, size_t, destinationSize, unsigned int, value);
00114 MOCKABLE_FUNCTION(, int, size_tToString, char*, destination, size_t, destinationSize, size_t, value);
00115 
00116 /*following logic shall define the TOUPPER and ISDIGIT, we do that because the SDK is not happy with some Arduino implementation of it.*/
00117 #define TOUPPER(c)      ((((c)>='a') && ((c)<='z'))?(c)-'a'+'A':c)
00118 #define ISDIGIT(c)      ((((c)>='0') && ((c)<='9'))?1:0)
00119 
00120 /*following logic shall define the ISNAN macro*/
00121 /*if runing on Microsoft Visual C compiler, than ISNAN shall be _isnan*/
00122 /*else if running on C99 or C11, ISNAN shall be isnan*/
00123 /*else if running on C89 ... #error and inform user*/
00124 
00125 #ifdef _MSC_VER
00126 #define ISNAN _isnan
00127 #else // _MSC_VER
00128 #if defined __STDC_VERSION__
00129 #if ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00130 /*C99 compiler or C11*/
00131 #define ISNAN isnan
00132 #else //  ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00133 #error update this file to contain the latest C standard.
00134 #endif // ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00135 #else // __STDC_VERSION__
00136 #ifdef __cplusplus
00137 /*C++ defines isnan... in C11*/
00138 extern "C++" {
00139 #define ISNAN std::isnan
00140 }
00141 #else // __cplusplus
00142 #error unknown (or C89) compiler, provide ISNAN with the same meaning as isnan in C99 standard  
00143 #endif // __cplusplus
00144 
00145 #endif // __STDC_VERSION__
00146 #endif // _MSC_VER
00147 
00148 #ifdef _MSC_VER
00149 #define INT64_PRINTF "%I64d"
00150 #else
00151 #if defined __STDC_VERSION__
00152 #if ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00153 /*C99 compiler or C11*/
00154 #define INT64_PRINTF "%" PRId64 ""
00155 #else // ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00156 #error update this file to contain the latest C standard.
00157 #endif // ((__STDC_VERSION__  == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
00158 #else // __STDC_VERSION__
00159 #ifdef __cplusplus 
00160 #define INT64_PRINTF "%" PRId64 ""
00161 #else // __cplusplus
00162 #error unknown (or C89) compiler, provide INT64_PRINTF with the same meaning as PRIdN in C99 standard
00163 #endif // __cplusplus
00164 #endif // __STDC_VERSION__
00165 #endif // _MSC_VER
00166 
00167 #ifdef __cplusplus
00168 }
00169 #endif // __cplusplus
00170 
00171 #endif /* CRT_ABSTRACTIONS_H */