From c4bfad07e371bc40c06fca90f2d77124d5566ec2 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 7 Jun 2010 21:03:03 -0400 Subject: 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. --- lcdgps.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lcdgps.c') diff --git a/lcdgps.c b/lcdgps.c index 1a7fbde5..25945f6f 100644 --- a/lcdgps.c +++ b/lcdgps.c @@ -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); } } -- cgit v1.2.1