From caf45e635c8a3f2446a19b77e7842030ec10d2de Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 18 Aug 2014 04:01:05 -0400 Subject: First part of Android port patches: deal with in_port_t. SUN_LEN, and getsid(). Also, fix how configuratuin in libgps_shm.c and smexport.h is handled. Based on a patch by Samuel Cuella , but cleaned up some to obey local conventions better. All regression tests pass. --- SConstruct | 28 +++++++++++++++++++++++++++- getsid.c | 16 ++++++++++++++++ libgps_shm.c | 6 ++++-- shmexport.c | 6 ++++-- 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 getsid.c diff --git a/SConstruct b/SConstruct index 0f39f5ce..e7c4cd16 100644 --- a/SConstruct +++ b/SConstruct @@ -588,6 +588,18 @@ else: bluezlibs = [] env["bluez"] = False + #in_port_t is not defined on Android + if not config.CheckType("in_port_t","#include "): + announce("Did not find in_port_t typedef, assuming unsigned short int") + confdefs.append("typedef unsigned short int in_port_t;\n") + + #SUN_LEN is not defined on Android + if not config.CheckDeclaration("SUN_LEN", "#include ") and not config.CheckDeclaration("SUN_LEN", "#include "): + announce("SUN_LEN is not system-defined, using local definition") + confdefs.append("#ifndef SUN_LEN\n") + confdefs.append("#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen((ptr)->sun_path))\n") + confdefs.append("#endif /* SUN_LEN */\n") + if config.CheckHeader(["bits/sockaddr.h", "linux/can.h"]): confdefs.append("#define HAVE_LINUX_CAN_H 1\n") announce("You have kernel CANbus available.") @@ -628,7 +640,7 @@ else: # check function after libraries, because some function require library # for example clock_gettime() require librt on Linux - for f in ("daemon", "strlcpy", "strlcat", "clock_gettime"): + for f in ("daemon", "strlcpy", "strlcat", "clock_gettime","getsid"): if config.CheckFunc(f): confdefs.append("#define HAVE_%s 1\n" % f.upper()) else: @@ -687,6 +699,7 @@ else: # ifdef __cplusplus extern "C" { # endif +#include size_t strlcat(/*@out@*/char *dst, /*@in@*/const char *src, size_t size); # ifdef __cplusplus } @@ -696,11 +709,23 @@ size_t strlcat(/*@out@*/char *dst, /*@in@*/const char *src, size_t size); # 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_GETSID +# ifdef __cplusplus +extern "C" { +# endif +#include +pid_t getsid(pid_t pid); +# ifdef __cplusplus +} +# endif +#endif + #define GPSD_CONFIG_H ''') @@ -785,6 +810,7 @@ libgps_sources = [ "rtcm3_json.c", "shared_json.c", "strl.c", + "getsid.c", ] if env['libgpsmm']: diff --git a/getsid.c b/getsid.c new file mode 100644 index 00000000..b6d5313f --- /dev/null +++ b/getsid.c @@ -0,0 +1,16 @@ +/* + * This file is Copyright (c) 2010 by the GPSD project + * BSD terms apply: see the file COPYING in the distribution root for details. + */ +#include "gpsd_config.h" + +#ifndef HAVE_GETSID +#include +#include + +/* This implementation is required for Android */ + +pid_t getsid(pid_t pid) { + return syscall(__NR_getsid, pid); +} +#endif /* HAVE_GETSID */ diff --git a/libgps_shm.c b/libgps_shm.c index 5f79aee2..c489af09 100644 --- a/libgps_shm.c +++ b/libgps_shm.c @@ -14,6 +14,10 @@ PERMISSIONS BSD terms apply: see the file COPYING in the distribution root for details. ***************************************************************************/ +#include "gpsd_config.h" + +#ifdef SHM_EXPORT_ENABLE + #include #include #include @@ -25,8 +29,6 @@ PERMISSIONS #include "gpsd.h" #include "libgps.h" -#ifdef SHM_EXPORT_ENABLE - /*@-matchfields@*/ struct privdata_t { diff --git a/shmexport.c b/shmexport.c index 3b764b57..f8645941 100644 --- a/shmexport.c +++ b/shmexport.c @@ -14,6 +14,10 @@ PERMISSIONS BSD terms apply: see the file COPYING in the distribution root for details. ***************************************************************************/ +#include "gpsd_config.h" + +#ifdef SHM_EXPORT_ENABLE + #include #include #include @@ -24,8 +28,6 @@ PERMISSIONS #include "gpsd.h" #include "libgps.h" /* for SHM_PSEUDO_FD */ -#ifdef SHM_EXPORT_ENABLE - /*@ -mustfreeonly -nullstate -mayaliasunique @*/ bool shm_acquire(struct gps_context_t *context) -- cgit v1.2.1