Skip to content

Commit

Permalink
Add custom stdbool file
Browse files Browse the repository at this point in the history
  • Loading branch information
muneebahmed10 committed Dec 2, 2020
1 parent ca492a4 commit d17fa1b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 17 deletions.
2 changes: 0 additions & 2 deletions MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Deviations from the MISRA standard are listed below:
| Rule 2.5 | Advisory | Allow unused macros. Library headers may define macros intended for the application's use, but are not used by a specific file. |
| Rule 3.1 | Required | Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks. |
| Rule 11.5 | Advisory | Allow casts from `void *`. Fields such as publish payloads are passed as `void *` and must be cast to the correct data type before use. |
| Rule 21.1 | Required | Allow use of all macro names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers. |
| Rule 21.2 | Required | Allow use of all macro and identifier names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers. |

### Flagged by Coverity
| Deviation | Category | Justification |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and build the library with default configuration values, provide `MQTT_DO_NOT_US

The [mqttFilePaths.cmake](mqttFilePaths.cmake) file contains the information of all source files and the header include path required to build the MQTT library.

Additionally, the MQTT library requires two header files that are not part of the ISO C90 standard library, `stdbool.h` and `stdint.h`. For compilers that do not provide these header files, the [source/include](source/include) directory contains the files [stdbool.readme](source/include/stdbool.readme) and [stdint.readme](source/include/stdint.readme), which can be renamed to `stdbool.h` and `stdint.h`, respectively, to provide the type definitions required by MQTT.

As mentioned in the previous section, either a custom config file (i.e. `core_mqtt_config.h`) OR `MQTT_DO_NOT_USE_CUSTOM_CONFIG` macro needs to be provided to build the MQTT library.

For a CMake example of building the MQTT library with the `mqttFilePaths.cmake` file, refer to the `coverity_analysis` library target in [test/CMakeLists.txt](test/CMakeLists.txt) file.
Expand Down
16 changes: 1 addition & 15 deletions source/include/core_mqtt_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,7 @@

#include <stddef.h>
#include <stdint.h>

/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore this section.
*/

/* bool is defined in only C99+. */
#if defined( __cplusplus ) || ( defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) )
#include <stdbool.h>
#elif !defined( bool ) && !defined( false ) && !defined( true )
#define bool int8_t
#define false ( int8_t ) 0
#define true ( int8_t ) 1
#endif
/** @endcond */
#include <stdbool.h>

/* MQTT_DO_NOT_USE_CUSTOM_CONFIG allows building the MQTT library
* without a custom config. If a custom config is provided, the
Expand Down
31 changes: 31 additions & 0 deletions source/include/stdbool.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#ifndef _STDBOOL_H
#define _STDBOOL_H

/*******************************************************************************
* This file contains the definitions specified in stdbool.h. It is provided to
* allow coreMQTT to be built using compilers that do not provide their own
* stdbool.h defintion.
*
* To use this file:
*
* 1) Copy this file into a directory that is in your compiler's include path.
* The directory must be part of the include path for system header files,
* for example passed using gcc's "-I" or "-isystem" options.
*
* 2) Rename the copied file stdbool.h.
*
*/

#ifndef __cplusplus

/* _Bool was introduced in C99. */
#define bool int
#define false 0
#define true 1

#endif

#define __bool_true_false_are_defined 1

#endif /* _STDBOOL_H */
29 changes: 29 additions & 0 deletions source/include/stdint.readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#ifndef _STDINT_H
#define _STDINT_H

/*******************************************************************************
* THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions
* necessary to build the coreMQTT code. It is provided to allow coreMQTT to be
* built using compilers that do not provide their own stdint.h definition.
*
* To use this file:
*
* 1) Copy this file into a directory that is in your compiler's include path.
* The directory must be part of the include path for system header file,
* for example passed using gcc's "-I" or "-isystem" options.
*
* 2) Rename the copied file stdint.h.
*
*/

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;

#define UINT16_MAX ( ( unsigned short ) 65535 )

#endif /* _STDINT_H */

0 comments on commit d17fa1b

Please sign in to comment.