diff --git a/NEWS b/NEWS index 0592bc0e..874f1242 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -$Id: NEWS,v 1.94 2006/03/14 12:05:16 rocky Exp $ +$Id: NEWS,v 1.95 2006/03/17 01:05:54 rocky Exp $ version 0.77cvs ===================================== @@ -40,6 +40,7 @@ version 0.77cvs is_device() when driver_id = DRIVER_UNKNOWN or DRIVER_DEVICE. OSX was freeing too much in listing drives. get_hwinfo was not respecting fixed-length field boundaries in image drivers (strcpy->strncpy). + iso9660_get_{l,d}time() anot accounting for the timezone properly. - small cdda-player improvements - shows more Cd-Text, and fix bug in non-interactive use (Yes, I sometimes use it.) @@ -336,4 +337,4 @@ version 0.1 Routines split off from VCDImager. -$Id: NEWS,v 1.94 2006/03/14 12:05:16 rocky Exp $ +$Id: NEWS,v 1.95 2006/03/17 01:05:54 rocky Exp $ diff --git a/lib/iso9660/iso9660.c b/lib/iso9660/iso9660.c index 6ca0eb0e..c6591a4f 100644 --- a/lib/iso9660/iso9660.c +++ b/lib/iso9660/iso9660.c @@ -1,5 +1,5 @@ /* - $Id: iso9660.c,v 1.20 2006/03/06 19:39:35 rocky Exp $ + $Id: iso9660.c,v 1.21 2006/03/17 01:05:54 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein @@ -43,6 +43,9 @@ const char ISO_STANDARD_ID[] = {'C', 'D', '0', '0', '1'}; #ifdef HAVE_STDIO_H #include #endif +#ifdef HAVE_STDLIB_H +#include +#endif #ifdef HAVE_SYS_STAT_H #include #endif @@ -51,7 +54,7 @@ const char ISO_STANDARD_ID[] = {'C', 'D', '0', '0', '1'}; #include #endif -static const char _rcsid[] = "$Id: iso9660.c,v 1.20 2006/03/06 19:39:35 rocky Exp $"; +static const char _rcsid[] = "$Id: iso9660.c,v 1.21 2006/03/17 01:05:54 rocky Exp $"; /* Variables to hold debugger-helping enumerations */ enum iso_enum1_s iso_enums1; @@ -136,32 +139,16 @@ iso9660_get_dtime (const iso9660_dtime_t *idr_date, bool b_localtime, p_tm->tm_mday = idr_date->dt_day; p_tm->tm_hour = idr_date->dt_hour; p_tm->tm_min = idr_date->dt_minute; - p_tm->tm_sec = idr_date->dt_second; + p_tm->tm_sec = idr_date->dt_second - idr_date->dt_gmtoff * (15 * 60); p_tm->tm_isdst = -1; /* information not available */ + + /* Recompute tm_wday and tm_yday via mktime. mktime will also renormalize + date values to account for the timezone offset. */ { time_t t = 0; struct tm *p_temp_tm = b_localtime ? localtime(&t): gmtime(&t); - /* Recompute tm_wday and tm_yday via mktime. Also adjust for - time-zone differences */ t = mktime(p_tm); - t -= idr_date->dt_gmtoff * (15 * 60); -#ifdef HAVE_TM_GMTOFF - t += p_temp_tm->tm_gmtoff; -#else - { - static bool i_first_time = true; - static time_t gmt_off; - if (i_first_time) { - struct tm tm_local, tm_gmt; - memcpy(&tm_local, localtime(&t), sizeof(struct tm)); - memcpy(&tm_gmt , gmtime(&t) , sizeof(struct tm)); - gmt_off = mktime(&tm_local) - mktime(&tm_gmt); - i_first_time = false; - } - t += gmt_off; - } -#endif p_temp_tm = b_localtime ? localtime(&t) : gmtime(&t); @@ -179,7 +166,10 @@ iso9660_get_dtime (const iso9660_dtime_t *idr_date, bool b_localtime, #define set_ltime_field(TM_FIELD, LT_FIELD, ADD_CONSTANT) \ { \ - p_tm->TM_FIELD = strtol(p_ldate->LT_FIELD, \ + char num[10]; \ + memcpy(num, p_ldate->LT_FIELD, sizeof(p_ldate->LT_FIELD)); \ + num[sizeof(p_ldate->LT_FIELD)+1] = '\0'; \ + p_tm->TM_FIELD = strtol(num, \ (char **)NULL, 10)+ADD_CONSTANT; \ if (0 != errno) return false; \ } @@ -194,24 +184,30 @@ iso9660_get_ltime (const iso9660_ltime_t *p_ldate, { if (!p_tm) return false; memset(p_tm, 0, sizeof(struct tm)); - set_ltime_field(tm_year, lt_year, 0); + set_ltime_field(tm_year, lt_year, -1900); set_ltime_field(tm_mon, lt_month, -1); set_ltime_field(tm_mday, lt_day, 0); set_ltime_field(tm_hour, lt_hour, 0); set_ltime_field(tm_min, lt_minute, 0); set_ltime_field(tm_sec, lt_second, 0); p_tm->tm_isdst= -1; /* information not available */ -#ifdef HAVE_TM_GMTOFF - p_tm->tm_gmtoff = - p_ldate->lt_gmtoff * (15 * 60); -#endif + p_tm->tm_sec += p_ldate->lt_gmtoff * (15 * 60); - /* Recompute tm_wday and tm_yday via mktime. */ + /* Recompute tm_wday and tm_yday via mktime. mktime will also renormalize + date values to account for the timezone offset. */ { time_t t; struct tm *p_temp_tm; - + const char *old_tzname=getenv("TZ"); + char psz_gmt_tzset[]="TZ=GMT"; + + putenv(psz_gmt_tzset); t = mktime(p_tm); p_temp_tm = gmtime(&t); + if (old_tzname) { + char psz_tzset[10]; + snprintf(psz_tzset, sizeof(psz_tzset), "TZ=%s", old_tzname); + } p_tm->tm_wday = p_temp_tm->tm_wday; p_tm->tm_yday = p_temp_tm->tm_yday; diff --git a/test/testiso9660.c b/test/testiso9660.c index 8e483ef6..2659723c 100644 --- a/test/testiso9660.c +++ b/test/testiso9660.c @@ -1,5 +1,5 @@ /* - $Id: testiso9660.c,v 1.8 2006/03/06 19:39:35 rocky Exp $ + $Id: testiso9660.c,v 1.9 2006/03/17 01:05:54 rocky Exp $ Copyright (C) 2003, 2006 Rocky Bernstein @@ -35,6 +35,80 @@ #endif #include +static bool +time_compare(struct tm *p_tm1, struct tm *p_tm2) +{ + bool okay = true; + if (!p_tm1) { + printf("get time is NULL\n"); + return false; + } + if (!p_tm2) { + printf("set time is NULL\n"); + return false; + } + if (p_tm1->tm_year != p_tm2->tm_year) { + printf("Years aren't equal. get: %d, set %d\n", + p_tm1->tm_year, p_tm2->tm_year); + okay=false; + } + if (p_tm1->tm_mon != p_tm2->tm_mon) { + printf("Months aren't equal. get: %d, set %d\n", + p_tm1->tm_mon, p_tm2->tm_mon); + okay=false; + } + if (p_tm1->tm_mday != p_tm2->tm_mday) { + printf("Month days aren't equal. get: %d, set %d\n", + p_tm1->tm_mday, p_tm2->tm_mday); + okay=false; + } + if (p_tm1->tm_min != p_tm2->tm_min) { + printf("minute aren't equal. get: %d, set %d\n", + p_tm1->tm_min, p_tm2->tm_min); + okay=false; + } + if (p_tm1->tm_hour != p_tm2->tm_hour) { + printf("hours aren't equal. get: %d, set %d\n", + p_tm1->tm_hour, p_tm2->tm_hour); + okay=false; + } + if (p_tm1->tm_sec != p_tm2->tm_sec) { + printf("seconds aren't equal. get: %d, set %d\n", + p_tm1->tm_sec, p_tm2->tm_sec); + okay=false; + } + if (p_tm1->tm_wday != p_tm2->tm_wday) { + printf("Week days aren't equal. get: %d, set %d\n", + p_tm1->tm_wday, p_tm2->tm_wday); + okay=false; + } + if (p_tm1->tm_yday != p_tm2->tm_yday) { + printf("Year days aren't equal. get: %d, set %d\n", + p_tm1->tm_yday, p_tm2->tm_yday); + okay=false; + } + if (p_tm1->tm_isdst != p_tm2->tm_isdst) { + printf("Is daylight savings times aren't equal. get: %d, set %d\n", + p_tm1->tm_isdst, p_tm2->tm_isdst); + okay=false; + } +#ifdef HAVE_TM_GMTOFF + if (p_tm1->tm_gmtoff != p_tm2->tm_gmtoff) { + printf("GMT offsets aren't equal. get: %ld, set %ld\n", + p_tm1->tm_gmtoff, p_tm2->tm_gmtoff); + okay=false; + } + if (p_tm1 != p_tm2) { + if (strcmp(p_tm1->tm_zone, p_tm2->tm_zone) != 0) { + printf("Time Zone values. get: %s, set %s\n", + p_tm1->tm_zone, p_tm2->tm_zone); + okay=false; + } + } +#endif + return okay; +} + int main (int argc, const char *argv[]) { @@ -158,6 +232,7 @@ main (int argc, const char *argv[]) { struct tm *p_tm, tm; iso9660_dtime_t dtime; + iso9660_ltime_t ltime; time_t now = time(NULL); memset(&dtime, 0, sizeof(dtime)); @@ -177,6 +252,14 @@ main (int argc, const char *argv[]) printf("set with iso9660_set_dtime().\n"); return 42; } + + iso9660_set_ltime(p_tm, <ime); + iso9660_get_ltime(<ime, &tm); + if ( ! time_compare(p_tm, &tm) ) { + printf("GMT time retrieved with iso9660_get_ltime() not same as that\n"); + printf("set with iso9660_set_ltime().\n"); + return 43; + } } return 0;