Files
bacnet_stack/src/bacnet/basic/sys/platform.h
T
Kari Argillander d92edd359f Fix couple compiler warnings (#737)
* linux/bip6: Use function over PRINTF macro

Our repo should be C89 compatibale. C89 does not support variac macros.
For this reason use variac functions. This also enables to print
different streams than just stderr.

Also now if something is changed in debug_fprintf it also affect here
which is good.

* Use __inline__ over inline in library

Use __inline__ over inline as that is C89/C90 combatible. With MSVC we
need to use __inline so just define __inline__ to it if not already.

* h_get_alarm_sum: Fix -Wself-assign compiler warning

We get Wself-assign if PRINT_ENABLED is 0

```
src/bacnet/basic/service/h_get_alarm_sum.c:129:16:
  warning: explicitly assigning value of variable of type 'int' to itself
  [-Wself-assign]
[build]   129 |     bytes_sent = bytes_sent;
[build]       |     ~~~~~~~~~~ ^ ~~~~~~~~~~
```

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-21 09:44:31 -05:00

116 lines
2.7 KiB
C

/**
* @file
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2022
* @brief Platform libc and compiler abstraction layer
* @details This libc and compiler abstraction layer assists with differences
* between compiler and libc versions, capabilities, and C standards.
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef BACNET_SYS_PLATFORM_H
#define BACNET_SYS_PLATFORM_H
#include <stddef.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#ifndef INT_MAX
#define INT_MAX (~0U >> 1U)
#endif
#ifndef islessgreater
#define islessgreater(x, y) ((x) < (y) || (x) > (y))
#endif
#ifndef isgreaterequal
#define isgreaterequal(x, y) ((x) > (y) || !islessgreater((x),(y)))
#endif
#ifndef islessequal
#define islessequal(x, y) ((x) < (y) || !islessgreater((x),(y)))
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) ((size_t)(sizeof(array) / sizeof((array)[0])))
#endif
/* marking some code as 'deprecated' */
#if defined(BACNET_STACK_DEPRECATED_DISABLE)
#define BACNET_STACK_DEPRECATED(message)
#elif defined(_MSC_VER)
#define BACNET_STACK_DEPRECATED(message) __declspec(deprecated(message))
#elif defined(__GNUC__)
#define BACNET_STACK_DEPRECATED(message) __attribute__((deprecated(message)))
#else
#define BACNET_STACK_DEPRECATED(message)
#endif
#if defined(_MSC_VER)
#ifndef strcasecmp
#define strcasecmp _stricmp
#endif
#ifndef strncasecmp
#define strncasecmp _strnicmp
#endif
#ifndef __inline__
#define __inline__ __inline
#endif
#if (_MSC_VER < 1900)
#include <stdio.h>
#include <stdarg.h>
#define snprintf c99_snprintf
#define vsnprintf c99_vsnprintf
__inline int c99_vsnprintf(
char *outBuf, size_t size, const char *format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
__inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = c99_vsnprintf(outBuf, size, format, ap);
va_end(ap);
return count;
}
#endif
#endif
/* some common min/max as defined in windef.h */
#ifndef NOMINMAX
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#endif /* NOMINMAX */
#if defined(__MINGW32__)
#define BACNET_STACK_FALLTHROUGH() /* fall through */
#elif defined(__GNUC__)
#define BACNET_STACK_FALLTHROUGH() __attribute__((fallthrough))
#else
#define BACNET_STACK_FALLTHROUGH() /* fall through */
#endif
#if defined(_MSC_VER)
/* Silence the warnings about unsafe versions of library functions */
/* as we need to keep the code portable */
#pragma warning(disable : 4996)
#endif
#endif