Skip to content

Commit

Permalink
Initial creation of os_compat.h.
Browse files Browse the repository at this point in the history
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 <time.h> 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.
  • Loading branch information
fhgwright committed Jan 22, 2017
1 parent 0fbb941 commit cb1403d
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 62 deletions.
51 changes: 0 additions & 51 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>
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 <string.h>
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 */
Expand Down
1 change: 1 addition & 0 deletions cgps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions gpsd.h-tail
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "gps.h"
#include "compiler.h"
#include "os_compat.h"

/*
* Constants for the VERSION response
Expand Down
2 changes: 1 addition & 1 deletion gpsdclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h> /* for strcasecmp() */
#include <time.h> /* for time_t */
#include <math.h>
#include <assert.h>

#include "gpsd_config.h"
#include "gps.h"
#include "gpsdclient.h"
#include "os_compat.h"

static struct exportmethod_t exportmethods[] = {
#if defined(DBUS_EXPORT_ENABLE)
Expand Down
1 change: 1 addition & 0 deletions gpsutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "gps.h"
#include "libgps.h"
#include "os_compat.h"

#ifdef USE_QT
#include <QDateTime>
Expand Down
3 changes: 1 addition & 2 deletions json.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ PERMISSIONS
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
#include <time.h> /* for time_t */
#include <ctype.h>

#include "gpsd_config.h" /* for strlcpy() prototype */
#include "os_compat.h"
#ifdef SOCKET_EXPORT_ENABLE
#include "json.h"

Expand Down
1 change: 0 additions & 1 deletion libgps_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ PERMISSIONS
/* sys/ipc.h needs _XOPEN_SOURCE, 500 means X/Open 1995 */
#define _XOPEN_SOURCE 500

#include <time.h> /* for time_t */
#include "gpsd_config.h"

#ifdef SHM_EXPORT_ENABLE
Expand Down
4 changes: 1 addition & 3 deletions os_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
* in the histories of those files.
*/

/* Determine which of these functions we need */
#include <time.h> /* 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

Expand Down
67 changes: 67 additions & 0 deletions os_compat.h
Original file line number Diff line number Diff line change
@@ -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 <time.h>

#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 <string.h>
size_t strlcat(char *dst, const char *src, size_t size);

#endif /* !HAVE_STRLCAT */

#ifndef HAVE_STRLCPY

#include <string.h>
size_t strlcpy(char *dst, const char *src, size_t size);

#endif /* !HAVE_STRLCPY */

# ifdef __cplusplus
}
# endif

#endif /* _GPSD_OS_COMPAT_H_ */
1 change: 1 addition & 0 deletions ppsthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@

#include "timespec.h"
#include "ppsthread.h"
#include "os_compat.h"

/*
* Tell GCC that we want thread-safe behavior with _REENTRANT;
Expand Down
1 change: 0 additions & 1 deletion shared_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ PERMISSIONS

#include <math.h>
#include <stdbool.h>
#include <time.h> /* for time_t */

#include "gpsd.h"
#ifdef SOCKET_EXPORT_ENABLE
Expand Down
1 change: 0 additions & 1 deletion shmexport.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ PERMISSIONS
/* sys/ipc.h needs _XOPEN_SOURCE, 500 means X/Open 1995 */
#define _XOPEN_SOURCE 500

#include <time.h> /* for time_t */
#include "gpsd_config.h"

#ifdef SHM_EXPORT_ENABLE
Expand Down
1 change: 0 additions & 1 deletion test_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h> /* for time_t */
#include <math.h>

#include "compiler.h"
Expand Down
1 change: 0 additions & 1 deletion test_timespec.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdint.h> /* required by C99, for int32_t */
#include <string.h>
#include <time.h> /* for time_t */
#include <math.h>
#include <unistd.h>

Expand Down

0 comments on commit cb1403d

Please sign in to comment.