From 52e03944c0a04a8fcec8a283293d08c5cc64c86f Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 27 Sep 2017 19:47:43 +0200 Subject: [PATCH] Move platform specific macros to a common header file --- msvc/libdivecomputer.vcproj | 4 ++++ src/Makefile.am | 1 + src/hw_ostc3.c | 5 +--- src/irda.c | 5 +--- src/platform.h | 44 ++++++++++++++++++++++++++++++++++++ src/suunto_eonsteel.c | 5 +--- src/suunto_eonsteel_parser.c | 12 +--------- 7 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 src/platform.h diff --git a/msvc/libdivecomputer.vcproj b/msvc/libdivecomputer.vcproj index c194f9f..242276a 100644 --- a/msvc/libdivecomputer.vcproj +++ b/msvc/libdivecomputer.vcproj @@ -692,6 +692,10 @@ RelativePath="..\include\libdivecomputer\parser.h" > + + diff --git a/src/Makefile.am b/src/Makefile.am index 387b284..97062e1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,6 +63,7 @@ libdivecomputer_la_SOURCES = \ diverite_nitekq.h diverite_nitekq.c diverite_nitekq_parser.c \ citizen_aqualand.h citizen_aqualand.c citizen_aqualand_parser.c \ divesystem_idive.h divesystem_idive.c divesystem_idive_parser.c \ + platform.h \ ringbuffer.h ringbuffer.c \ rbstream.h rbstream.c \ checksum.h checksum.c \ diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index a1a5efd..7ce7fd5 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -30,10 +30,7 @@ #include "serial.h" #include "array.h" #include "aes.h" - -#ifdef _MSC_VER -#define snprintf _snprintf -#endif +#include "platform.h" #define ISINSTANCE(device) dc_device_isinstance((device), &hw_ostc3_device_vtable) diff --git a/src/irda.c b/src/irda.c index 0f20970..d085ec0 100644 --- a/src/irda.c +++ b/src/irda.c @@ -53,6 +53,7 @@ #include "common-private.h" #include "context-private.h" #include "array.h" +#include "platform.h" #ifdef _WIN32 typedef int s_ssize_t; @@ -82,10 +83,6 @@ typedef int s_errcode_t; #define S_CLOSE close #endif -#ifdef _MSC_VER -#define snprintf _snprintf -#endif - struct dc_irda_t { dc_context_t *context; #ifdef _WIN32 diff --git a/src/platform.h b/src/platform.h new file mode 100644 index 0000000..f1d8155 --- /dev/null +++ b/src/platform.h @@ -0,0 +1,44 @@ +/* + * libdivecomputer + * + * Copyright (C) 2017 Jef Driesen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef DC_PLATFORM_H +#define DC_PLATFORM_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef _MSC_VER +#define snprintf _snprintf +#define strcasecmp _stricmp +#if _MSC_VER < 1800 +// The rint() function is only available in MSVC 2013 and later +// versions. Our replacement macro isn't entirely correct, because the +// rounding rules for halfway cases are slightly different (away from +// zero vs to even). But for our use-case, that's not a problem. +#define rint(x) ((x) >= 0.0 ? floor((x) + 0.5): ceil((x) - 0.5)) +#endif +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DC_PLATFORM_H */ diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 2e6d4c4..09f21a9 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -28,10 +28,7 @@ #include "device-private.h" #include "array.h" #include "usbhid.h" - -#ifdef _MSC_VER -#define snprintf _snprintf -#endif +#include "platform.h" typedef struct suunto_eonsteel_device_t { dc_device_t base; diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 0ebee01..a7f817d 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -28,17 +28,7 @@ #include "context-private.h" #include "parser-private.h" #include "array.h" - -#ifdef _MSC_VER -#define strcasecmp _stricmp -#if _MSC_VER < 1800 -// The rint() function is only available in MSVC 2013 and later -// versions. Our replacement macro isn't entirely correct, because the -// rounding rules for halfway cases are slightly different (away from -// zero vs to even). But for our use-case, that's not a problem. -#define rint(x) ((x) >= 0.0 ? floor((x) + 0.5): ceil((x) - 0.5)) -#endif -#endif +#include "platform.h" #define C_ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))