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..877e320 --- /dev/null +++ b/src/platform.h @@ -0,0 +1,50 @@ +/* + * 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 _WIN32 +#define DC_PRINTF_SIZE "%Iu" +#else +#define DC_PRINTF_SIZE "%zu" +#endif + +#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..07cd85c 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; @@ -140,7 +137,7 @@ static int receive_packet(suunto_eonsteel_device_t *eon, unsigned char *buffer, return -1; } if (transferred != PACKET_SIZE) { - ERROR(eon->base.context, "incomplete read interrupt transfer (got %zu, expected %d)", transferred, PACKET_SIZE); + ERROR(eon->base.context, "incomplete read interrupt transfer (got " DC_PRINTF_SIZE ", expected %d)", transferred, PACKET_SIZE); return -1; } if (buf[0] != 0x3f) { 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))) diff --git a/src/uwatec_g2.c b/src/uwatec_g2.c index 6e35104..f6b0b02 100644 --- a/src/uwatec_g2.c +++ b/src/uwatec_g2.c @@ -28,6 +28,7 @@ #include "device-private.h" #include "usbhid.h" #include "array.h" +#include "platform.h" #define ISINSTANCE(device) dc_device_isinstance((device), &uwatec_g2_device_vtable) @@ -76,7 +77,7 @@ receive_data (uwatec_g2_device_t *device, dc_event_progress_t *progress, unsigne return rc; } if (transferred != PACKET_SIZE) { - ERROR (device->base.context, "incomplete read interrupt transfer (got %zu, expected %d)", transferred, PACKET_SIZE); + ERROR (device->base.context, "incomplete read interrupt transfer (got " DC_PRINTF_SIZE ", expected %d)", transferred, PACKET_SIZE); return DC_STATUS_PROTOCOL; } len = buf[0];