diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-09-20 11:41:44 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-09-20 11:41:44 -0700 |
commit | 574d4d4facb83ee5505a988f5dc5830602fc8048 (patch) | |
tree | 066da5a9aed77f145f5c942d2780df298a6a6b2d /dive.h | |
parent | f4bc0ca37b47fd731bf55bc6c4675a34092771da (diff) | |
parent | 6d16a15196857eb4fe2eb4ca3cf363f1221afe60 (diff) | |
download | subsurface-574d4d4facb83ee5505a988f5dc5830602fc8048.tar.gz |
Merge branch 'time-function'
Merge the 64-bit timestamp_t time function branch.
This makes subsurface not only safe against the 2038-year problem, but
also avoids the use of thread-unsafe gmtime() etc.
We still use the system time_t for initializing the calendar widget for
adding a new dive, but that's cosmetic rather than anything fundamental.
* time-function:
FIND_TRIP: don't cast a timestamp to a pointer
dive-time widget: fix incorrect use of timestamp_t
Fix the incorrect data type for DIVE_DATE accesses
Use a 64-bit 'timestamp_t' for all timestamps, rather than 'time_t'
Diffstat (limited to 'dive.h')
-rw-r--r-- | dive.h | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -236,6 +236,7 @@ struct event { #define W_IDX_PRIMARY 0 #define W_IDX_SECONDARY 1 +typedef gint64 timestamp_t; typedef enum { TF_NONE, NO_TRIP, IN_TRIP, NUM_TRIPFLAGS } tripflag_t; extern const char *tripflag_names[NUM_TRIPFLAGS]; @@ -244,7 +245,7 @@ struct dive { tripflag_t tripflag; struct dive *divetrip; int selected; - time_t when; + timestamp_t when; char *location; char *notes; char *divemaster, *buddy; @@ -288,11 +289,17 @@ static inline int dive_date_cmp(gconstpointer _a, gconstpointer _b) { } /* returns 0 if the dive happened exactly at time */ -static inline int dive_when_find(gconstpointer _dive, gconstpointer _time) { - return ((struct dive *)_dive)->when != (time_t) _time; +static inline int dive_when_find(gconstpointer _listentry, gconstpointer _when) +{ + const struct dive *dive = _listentry; + const timestamp_t *tsp = _when; + return dive->when != *tsp; } -#define FIND_TRIP(_when) g_list_find_custom(dive_trip_list, (gconstpointer)(_when), dive_when_find) +static inline GList *FIND_TRIP(timestamp_t *when) +{ + return g_list_find_custom(dive_trip_list, when, dive_when_find); +} #ifdef DEBUG_TRIP static void dump_trip_list(void) @@ -300,9 +307,10 @@ static void dump_trip_list(void) GList *p = NULL; int i=0; while ((p = NEXT_TRIP(p))) { - struct tm *tm = gmtime(&DIVE_TRIP(p)->when); + struct tm tm; + utc_mkdate(DIVE_TRIP(p)->when, &tm); printf("trip %d to \"%s\" on %04u-%02u-%02u %02u:%02u:%02u\n", ++i, DIVE_TRIP(p)->location, - tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + tm.tm_year + 1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); } printf("-----\n"); } @@ -314,7 +322,7 @@ static void dump_trip_list(void) static void inline insert_trip(struct dive **trip) { struct dive *dive_trip = *trip; - GList *result = FIND_TRIP(dive_trip->when); + GList *result = FIND_TRIP(&dive_trip->when); if (result) { if (! DIVE_TRIP(result)->location) DIVE_TRIP(result)->location = dive_trip->location; @@ -412,7 +420,8 @@ static inline unsigned int dive_size(int samples) return sizeof(struct dive) + samples*sizeof(struct sample); } -extern time_t utc_mktime(struct tm *tm); +extern timestamp_t utc_mktime(struct tm *tm); +extern void utc_mkdate(timestamp_t, struct tm *tm); extern struct dive *alloc_dive(void); extern void record_dive(struct dive *dive); |