Эх сурвалжийг харах

minmea.h: add Windows compatibility layer

Kosma Moczek 7 жил өмнө
parent
commit
0b02771b28
3 өөрчлөгдсөн 36 нэмэгдсэн , 2 устгасан
  1. 10 2
      README.md
  2. 23 0
      compat/minmea_compat_windows.h
  3. 3 0
      minmea.h

+ 10 - 2
README.md

@@ -13,6 +13,7 @@ systems.
 * No floating point usage in the core library.
 * Supports both fixed and floating point values.
 * One source file and one header - can't get any simpler.
+* Tested under Linux, OS X, Windows and embedded ARM GCC.
 * Easily extendable to support new sentences.
 * Complete with a test suite and static analysis.
 
@@ -29,6 +30,14 @@ systems.
 
 Adding support for more sentences is trivial; see ``minmea.c`` source. Good documentation on NMEA is at http://www.catb.org/gpsd/NMEA.html
 
+## Compatibility
+
+Minmea runs out-of-the-box under most Unix-compatible systems. Support for non-Unix systems
+(including native Windows builds under MSVC) is provided via compatibility headers:
+
+1. Define `MINMEA_INCLUDE_COMPAT` in the build environment.
+2. Add appropriate compatibility header from under `compat/` directory as `minmea_compat.h`.
+
 ## Fractional number format
 
 Internally, minmea stores fractional numbers as pairs of two integers: ``{value, scale}``.
@@ -131,8 +140,7 @@ typing ``make``.
   (or equivalent) to remove the unused functions (parsers) from the final image.
 * Some systems lack ``timegm``. On these systems, the recommended course of
   action is to build with ``-Dtimegm=mktime`` which will work correctly as long
-  the system runs in the default ``UTC`` timezone. Native Windows builds should
-  use ``-Dtimegm=_mkgmtime`` instead which will work correctly in all timezones.
+  the system runs in the default ``UTC`` timezone.
 
 ## Bugs
 

+ 23 - 0
compat/minmea_compat_windows.h

@@ -0,0 +1,23 @@
+/*
+ * Copyright © 2017 Kosma Moczek <kosma@cloudyourcar.com>
+ * This program is free software. It comes without any warranty, to the extent
+ * permitted by applicable law. You can redistribute it and/or modify it under
+ * the terms of the Do What The Fuck You Want To Public License, Version 2, as
+ * published by Sam Hocevar. See the COPYING file for more details.
+ */
+
+#if defined(_MSC_VER)
+
+#if !defined(HAVE_STRUCT_TIMESPEC)
+struct timespec {
+    time_t tv_sec;
+    long tv_nsec;
+};
+#endif
+
+#define inline __inline
+#define timegm _mkgmtime
+
+#endif
+
+/* vim: set ts=4 sw=4 et: */

+ 3 - 0
minmea.h

@@ -19,6 +19,9 @@ extern "C" {
 #include <errno.h>
 #include <time.h>
 #include <math.h>
+#ifdef MINMEA_INCLUDE_COMPAT
+#include <minmea_compat.h>
+#endif
 
 #define MINMEA_MAX_LENGTH 80