diff options
author | Fred Wright <fw@fwright.net> | 2017-01-21 18:31:39 -0800 |
---|---|---|
committer | Fred Wright <fw@fwright.net> | 2017-01-22 14:02:55 -0800 |
commit | 0fbb94143ec4a5baf569b09937b28d4339cc8a00 (patch) | |
tree | 02801d327eecfcba2126757f655c0eca82f20ce0 /os_compat.c | |
parent | 390b32f32c166ff8e5a04390cca75247993be73c (diff) | |
download | gpsd-0fbb94143ec4a5baf569b09937b28d4339cc8a00.tar.gz |
Cleans up some ordering in os_compat.c.
This rearranges the order of some conditionals and includes, in order
to avoid some gratuitous includes where unnecessary.
Due to the fact that some actual definitions for the clock_gettime
fallback are embedded directly in gpsd_config.h, it's necessary to
include <time.h> prior to including it. This will be fixed once the
relevant definitions are moved to the upcoming os_compat.h.
This also replaces the "UNUSED" in clock_gettime with a void cast,
eliminating the need for compiler.h.
TESTED:
Ran "scons build-all check" on OSX 10.9, OSX 10.12 (which has real
clock_gettime) and Ubuntu 14. Also verified that the clock_gettime
fallback is present in OSX 10.9, but absent in OSX 10.12 and in Ubuntu
14.
Diffstat (limited to 'os_compat.c')
-rw-r--r-- | os_compat.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/os_compat.c b/os_compat.c index 95b38579..6e11ee89 100644 --- a/os_compat.c +++ b/os_compat.c @@ -13,15 +13,17 @@ * 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" + +#ifndef HAVE_CLOCK_GETTIME + /* Simulate ANSI/POSIX clock_gettime() on platforms that don't have it */ #include <time.h> #include <sys/time.h> -#include "compiler.h" - -#ifndef HAVE_CLOCK_GETTIME - /* * Note that previous versions of this code made use of clock_get_time() * on OSX, as a way to get time of day with nanosecond resolution. But @@ -30,8 +32,9 @@ * gettimeofday(). Thus, it makes no sense to do anything special for OSX. */ -int clock_gettime(clockid_t clk_id UNUSED, struct timespec *ts) +int clock_gettime(clockid_t clk_id, struct timespec *ts) { + (void) clk_id; struct timeval tv; if (gettimeofday(&tv, NULL) < 0) return -1; @@ -43,6 +46,8 @@ int clock_gettime(clockid_t clk_id UNUSED, struct timespec *ts) /* End of clock_gettime section */ +#ifndef HAVE_DAEMON + /* Simulate Linux/BSD daemon() on platforms that don't have it */ #include <stdlib.h> @@ -51,8 +56,6 @@ int clock_gettime(clockid_t clk_id UNUSED, struct timespec *ts) #include <fcntl.h> #include <unistd.h> -#include "gpsd_config.h" -#ifndef HAVE_DAEMON #if defined (HAVE_PATH_H) #include <paths.h> #else @@ -96,10 +99,6 @@ int daemon(int nochdir, int noclose) /* Provide BSD strlcat()/strlcpy() on platforms that don't have it */ -#include <string.h> -#include <time.h> /* for time_t */ -#include "gpsd_config.h" - /* * These versions use memcpy and strlen() because they are often * heavily optimized down to assembler level. Thus, likely to be @@ -107,6 +106,9 @@ int daemon(int nochdir, int noclose) */ #ifndef HAVE_STRLCAT + +#include <string.h> + /* * Appends src to string dst of size siz (unlike strncat, siz is the * full size of dst, not space left). At most siz-1 characters @@ -178,6 +180,9 @@ size_t strlcat(char *dst, const char *src, size_t siz) #endif /* HAVE_STRLCAT */ #ifndef HAVE_STRLCPY + +#include <string.h> + /* * Copy src to string dst of size siz. At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). |