#define _DEFAULT_SOURCE
#define _XOPEN_SOURCE
+#define _BSD_SOURCE
#include <time.h>
#include <sys/types.h>
&tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 3) {
ERROR("failed to parse date '%s'\n", nmea_params[9].str);
}
+ else if (tm.tm_year == 0) {
+ DEBUG(4, "waiting for valid date\n");
+ return;
+ }
else {
tm.tm_year += 100; /* year starts with 1900 */
tm.tm_mon -= 1; /* month starts with 0 */
DEBUG(3, "date: %s UTC\n", tmp);
if (adjust_clock) {
- struct timeval tv = { timegm(&tm), 0 };
+ time_t sec = timegm(&tm);
struct timeval cur;
gettimeofday(&cur, NULL);
- if (abs(cur.tv_sec - tv.tv_sec) > MAX_TIME_OFFSET) {
+ if ((sec < 0) || (llabs(cur.tv_sec - sec) > MAX_TIME_OFFSET)) {
+ struct timeval tv = { 0 };
+ tv.tv_sec = sec;
if (++nmea_bad_time > MAX_BAD_TIME) {
LOG("system time differs from GPS time by more than %d seconds. Using %s UTC as the new time\n", MAX_TIME_OFFSET, tmp);
/* only set datetime if specified by command line argument! */
}
if (strlen(nmea_params[3].str) < 9 || strlen(nmea_params[5].str) < 10) {
- ERROR("lat/lng have invalid string length %d<9, %d<10\n",
+ ERROR("lat/lng have invalid string length %zu<9, %zu<10\n",
strlen(nmea_params[3].str), strlen(nmea_params[5].str));
} else {
float minutes;
nmea_process(char *a)
{
char *csum;
- int cnt, i;
+ int cnt;
+ unsigned int i;
if (strncmp(a, "$GP", 3))
return;