From cb1403d842a2fdbe6109eaf48acb7a494f30784d Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Sun, 22 Jan 2017 00:11:34 -0800 Subject: Initial creation of os_compat.h. This creates a header for os_compat.c, and moves the related prototypes into it from gpsd_config.h (as created by SConstruct), after adding references to it to gpsd.h (via gpsd.h-tail) and a few other sources that need it but don't include gpsd.h. It also removes includes of in the places where they were only needed for the code now removed from gpsd_config.h. TESTED: Ran "scons build-all check" on OSX 10.9 (with strlcat/strlcpy but no clock_gettime), OSX 10.12 (with strlcat/strlcpy and clock_gettime), and Ubuntu 14 (with clock_gettime but no strlcat/strlcpy). Also verified that fallback versions were not being included where unnecessary. --- SConstruct | 51 ------------------------------------------- cgps.c | 1 + gpsd.h-tail | 1 + gpsdclient.c | 2 +- gpsutils.c | 1 + json.c | 3 +-- libgps_shm.c | 1 - os_compat.c | 4 +--- os_compat.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ppsthread.c | 1 + shared_json.c | 1 - shmexport.c | 1 - test_matrix.c | 1 - test_timespec.c | 1 - 14 files changed, 74 insertions(+), 62 deletions(-) create mode 100644 os_compat.h diff --git a/SConstruct b/SConstruct index d6922788..41698da0 100644 --- a/SConstruct +++ b/SConstruct @@ -860,57 +860,6 @@ else: confdefs.append('''\ -/* Some libcs do not have strlcat/strlcpy. Local copies are provided */ -#ifndef HAVE_STRLCAT -# ifdef __cplusplus -extern "C" { -# endif -#include -size_t strlcat(/*@out@*/char *dst, /*@in@*/const char *src, size_t size); -# ifdef __cplusplus -} -# endif -#endif -#ifndef HAVE_STRLCPY -# ifdef __cplusplus -extern "C" { -# endif -#include -size_t strlcpy(/*@out@*/char *dst, /*@in@*/const char *src, size_t size); -# ifdef __cplusplus -} -# endif -#endif -#ifndef HAVE_CLOCK_GETTIME -# ifdef __cplusplus -extern "C" { -# endif -#ifndef CLOCKID_T_DEFINED -typedef int clockid_t; -#define CLOCKID_T_DEFINED -# endif -/* - * OS X 10.5 and later use _STRUCT_TIMESPEC (like other OSes) - * 10.4 uses _TIMESPEC - * 10.3 and earlier use _TIMESPEC_DECLARED - */ -#if !defined(_STRUCT_TIMESPEC) && \ - !defined(_TIMESPEC) && \ - !defined(_TIMESPEC_DECLARED) && \ - !defined(__timespec_defined) -#define _STRUCT_TIMESPEC -struct timespec { - time_t tv_sec; - long tv_nsec; -}; -#endif -/* OS X does not have clock_gettime */ -#define CLOCK_REALTIME 0 -int clock_gettime(clockid_t, struct timespec *); -# ifdef __cplusplus -} -# endif -#endif #define GPSD_CONFIG_H #endif /* GPSD_CONFIG_H */ diff --git a/cgps.c b/cgps.c index e5b749a3..56f90736 100644 --- a/cgps.c +++ b/cgps.c @@ -101,6 +101,7 @@ #include "compiler.h" /* for UNUSED */ #include "gpsdclient.h" #include "revision.h" +#include "os_compat.h" static struct gps_data_t gpsdata; static time_t status_timer; /* Time of last state change. */ diff --git a/gpsd.h-tail b/gpsd.h-tail index d1fb5ead..72b3abd4 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -11,6 +11,7 @@ #include "gps.h" #include "compiler.h" +#include "os_compat.h" /* * Constants for the VERSION response diff --git a/gpsdclient.c b/gpsdclient.c index 70093b4a..b1b679be 100644 --- a/gpsdclient.c +++ b/gpsdclient.c @@ -8,13 +8,13 @@ #include #include #include /* for strcasecmp() */ -#include /* for time_t */ #include #include #include "gpsd_config.h" #include "gps.h" #include "gpsdclient.h" +#include "os_compat.h" static struct exportmethod_t exportmethods[] = { #if defined(DBUS_EXPORT_ENABLE) diff --git a/gpsutils.c b/gpsutils.c index 254cd552..7c6dbd0a 100644 --- a/gpsutils.c +++ b/gpsutils.c @@ -21,6 +21,7 @@ #include "gps.h" #include "libgps.h" +#include "os_compat.h" #ifdef USE_QT #include diff --git a/json.c b/json.c index ed440e72..f5b59fba 100644 --- a/json.c +++ b/json.c @@ -67,10 +67,9 @@ PERMISSIONS #include #include #include -#include /* for time_t */ #include -#include "gpsd_config.h" /* for strlcpy() prototype */ +#include "os_compat.h" #ifdef SOCKET_EXPORT_ENABLE #include "json.h" diff --git a/libgps_shm.c b/libgps_shm.c index a9250ca0..6d065ced 100644 --- a/libgps_shm.c +++ b/libgps_shm.c @@ -18,7 +18,6 @@ PERMISSIONS /* sys/ipc.h needs _XOPEN_SOURCE, 500 means X/Open 1995 */ #define _XOPEN_SOURCE 500 -#include /* for time_t */ #include "gpsd_config.h" #ifdef SHM_EXPORT_ENABLE diff --git a/os_compat.c b/os_compat.c index 6e11ee89..4ffefb08 100644 --- a/os_compat.c +++ b/os_compat.c @@ -13,9 +13,7 @@ * in the histories of those files. */ -/* Determine which of these functions we need */ -#include /* For time_t (temp until we fix gpsd_config.h) */ -#include "gpsd_config.h" +#include "os_compat.h" /* Includes gpsd_config.h */ #ifndef HAVE_CLOCK_GETTIME diff --git a/os_compat.h b/os_compat.h new file mode 100644 index 00000000..4dbe9de3 --- /dev/null +++ b/os_compat.h @@ -0,0 +1,67 @@ +/* + * This file is Copyright (c) 2017 by the GPSD project + * BSD terms apply: see the file COPYING in the distribution root for details. + * + * This is the header for os_compat.c, which contains functions dealing with + * compatibility issues across OSes. + */ +#ifndef _GPSD_OS_COMPAT_H_ +#define _GPSD_OS_COMPAT_H_ + +/* Determine which of these functions we need */ +#include "gpsd_config.h" + +# ifdef __cplusplus +extern "C" { +# endif + +#ifndef HAVE_CLOCK_GETTIME + +#include + +#ifndef CLOCKID_T_DEFINED +typedef int clockid_t; +#define CLOCKID_T_DEFINED +#endif /* !CLOCKID_T_DEFINED */ + +/* + * OS X 10.5 and later use _STRUCT_TIMESPEC (like other OSes) + * 10.4 uses _TIMESPEC + * 10.3 and earlier use _TIMESPEC_DECLARED + */ +#if !defined(_STRUCT_TIMESPEC) && \ + !defined(_TIMESPEC) && \ + !defined(_TIMESPEC_DECLARED) && \ + !defined(__timespec_defined) +#define _STRUCT_TIMESPEC +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#endif /* !_STRUCT_TIMESPEC ... */ + +/* OS X does not have clock_gettime */ +#define CLOCK_REALTIME 0 +int clock_gettime(clockid_t, struct timespec *); + +#endif /* !HAVE_CLOCK_GETTIME */ + +#ifndef HAVE_STRLCAT + +#include +size_t strlcat(char *dst, const char *src, size_t size); + +#endif /* !HAVE_STRLCAT */ + +#ifndef HAVE_STRLCPY + +#include +size_t strlcpy(char *dst, const char *src, size_t size); + +#endif /* !HAVE_STRLCPY */ + +# ifdef __cplusplus +} +# endif + +#endif /* _GPSD_OS_COMPAT_H_ */ diff --git a/ppsthread.c b/ppsthread.c index 53a93b2e..6aadf90d 100644 --- a/ppsthread.c +++ b/ppsthread.c @@ -84,6 +84,7 @@ #include "timespec.h" #include "ppsthread.h" +#include "os_compat.h" /* * Tell GCC that we want thread-safe behavior with _REENTRANT; diff --git a/shared_json.c b/shared_json.c index a1589421..3cabccc4 100644 --- a/shared_json.c +++ b/shared_json.c @@ -17,7 +17,6 @@ PERMISSIONS #include #include -#include /* for time_t */ #include "gpsd.h" #ifdef SOCKET_EXPORT_ENABLE diff --git a/shmexport.c b/shmexport.c index cef94d77..2edf0776 100644 --- a/shmexport.c +++ b/shmexport.c @@ -18,7 +18,6 @@ PERMISSIONS /* sys/ipc.h needs _XOPEN_SOURCE, 500 means X/Open 1995 */ #define _XOPEN_SOURCE 500 -#include /* for time_t */ #include "gpsd_config.h" #ifdef SHM_EXPORT_ENABLE diff --git a/test_matrix.c b/test_matrix.c index a1249cba..b7e78851 100644 --- a/test_matrix.c +++ b/test_matrix.c @@ -8,7 +8,6 @@ #include #include #include -#include /* for time_t */ #include #include "compiler.h" diff --git a/test_timespec.c b/test_timespec.c index 315d974a..80644684 100644 --- a/test_timespec.c +++ b/test_timespec.c @@ -8,7 +8,6 @@ #include #include /* required by C99, for int32_t */ #include -#include /* for time_t */ #include #include -- cgit v1.2.1