minmea.h: add Windows compatibility layer

This commit is contained in:
Kosma Moczek 2017-10-23 18:53:48 +02:00
parent ded4faf483
commit 0b02771b28
3 changed files with 36 additions and 2 deletions

View File

@ -13,6 +13,7 @@ systems.
* No floating point usage in the core library. * No floating point usage in the core library.
* Supports both fixed and floating point values. * Supports both fixed and floating point values.
* One source file and one header - can't get any simpler. * 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. * Easily extendable to support new sentences.
* Complete with a test suite and static analysis. * 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 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 ## Fractional number format
Internally, minmea stores fractional numbers as pairs of two integers: ``{value, scale}``. 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. (or equivalent) to remove the unused functions (parsers) from the final image.
* Some systems lack ``timegm``. On these systems, the recommended course of * Some systems lack ``timegm``. On these systems, the recommended course of
action is to build with ``-Dtimegm=mktime`` which will work correctly as long 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 the system runs in the default ``UTC`` timezone.
use ``-Dtimegm=_mkgmtime`` instead which will work correctly in all timezones.
## Bugs ## Bugs

View File

@ -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: */

View File

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