diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2018-12-27 05:39:42 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2018-12-27 05:39:42 -0500 |
commit | 1998c0301f6f9542bf5dd51e8d18f3d7f4e76023 (patch) | |
tree | 47b092141978039c773e4a4e9f992eab90ee340b /gpsutils.c | |
parent | e81cfb77ab1a8de2e7cac6883e632124bcbe6f35 (diff) | |
download | gpsd-1998c0301f6f9542bf5dd51e8d18f3d7f4e76023.tar.gz |
Factor most uses of pselect(2) into a new utility function named 'nanowait'.
Also, remove sime header inclusions discovered to be unnecessary during
the change.
Diffstat (limited to 'gpsutils.c')
-rw-r--r-- | gpsutils.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -10,6 +10,11 @@ * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_01_02 */ #define _XOPEN_SOURCE 600 +#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L +/* pselect() needs _POSIX_C_SOURCE >= 200112L */ +#define _POSIX_C_SOURCE 200112L +#endif + #include <stdio.h> #include <time.h> #include <sys/time.h> @@ -18,10 +23,12 @@ #include <math.h> #include <errno.h> #include <ctype.h> +#include <sys/time.h> /* expected to have a pselect(2) prototype a la SuS */ #include "gps.h" #include "libgps.h" #include "os_compat.h" +#include "timespec.h" #ifdef USE_QT #include <QDateTime> @@ -621,4 +628,16 @@ double earth_distance(double lat1, double lon1, double lat2, double lon2) return earth_distance_and_bearings(lat1, lon1, lat2, lon2, NULL, NULL); } +bool nanowait(int fd, int nanoseconds) +{ + fd_set fdset; + struct timespec to; + + FD_ZERO(&fdset); + FD_SET(fd, &fdset); + to.tv_sec = nanoseconds / NS_IN_SEC; + to.tv_nsec = nanoseconds % NS_IN_SEC; + return pselect(fd + 1, &fdset, NULL, NULL, &to, NULL) == 1; +} + /* end */ |