diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2010-06-07 21:03:03 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2010-06-07 21:03:03 -0400 |
commit | c4bfad07e371bc40c06fca90f2d77124d5566ec2 (patch) | |
tree | 864e8cd57c840e6b4d5a91fb8f9ea00aa81ddc0a /lcdgps.c | |
parent | ef549333bb4f161cd97c3977a00d97cda906be02 (diff) | |
download | gpsd-c4bfad07e371bc40c06fca90f2d77124d5566ec2.tar.gz |
Use re-entrant open in the C examples.
In the next mahor API change the non-re-rentrant call will go away.
All regression tests passm, code splints clean.
Diffstat (limited to 'lcdgps.c')
-rw-r--r-- | lcdgps.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -94,7 +94,7 @@ ssize_t sockwriteline(int sockd,const void *vptr,size_t n); int send_lcd(char *buf); static struct fixsource_t source; -static struct gps_data_t *gpsdata; +static struct gps_data_t gpsdata; static float altfactor = METERS_TO_FEET; static float speedfactor = MPS_TO_MPH; static char *altunits = "ft"; @@ -471,8 +471,7 @@ int main(int argc, char *argv[]) daemonize(); /* Open the stream to gpsd. */ - /*@i@*/gpsdata = gps_open(source.server, source.port); - if (!gpsdata) { + if (gps_open_r(source.server, source.port, &gpsdata) != 0) { (void)fprintf( stderr, "cgps: no gpsd running or network error: %d, %s\n", errno, gps_errstr(errno)); @@ -520,21 +519,21 @@ int main(int argc, char *argv[]) reset_lcd(); /* Here's where updates go. */ - gps_set_raw_hook(gpsdata, update_lcd); - gps_stream(gpsdata, WATCH_ENABLE, NULL); + gps_set_raw_hook(&gpsdata, update_lcd); + gps_stream(&gpsdata, WATCH_ENABLE, NULL); for (;;) { /* heart of the client */ /* watch to see when it has input */ FD_ZERO(&rfds); - FD_SET(gpsdata->gps_fd, &rfds); + FD_SET(gpsdata.gps_fd, &rfds); /* wait up to five seconds. */ timeout.tv_sec = 5; timeout.tv_usec = 0; /* check if we have new information */ - data = select(gpsdata->gps_fd + 1, &rfds, NULL, NULL, &timeout); + data = select(gpsdata.gps_fd + 1, &rfds, NULL, NULL, &timeout); if (data == -1) { fprintf( stderr, "cgps: socket error\n"); @@ -542,7 +541,7 @@ int main(int argc, char *argv[]) } else if (data) { /* code that calls gps_poll(gpsdata) */ - (void)gps_poll(gpsdata); + (void)gps_poll(&gpsdata); } } |