diff options
author | Markus Minichmayr <markus@tapkey.com> | 2022-02-23 15:39:05 +0100 |
---|---|---|
committer | Allen Winter <allen.winter@kdab.com> | 2022-06-03 11:17:08 -0400 |
commit | acf1ae1dacb43f967b289e0922856703c1e15d1f (patch) | |
tree | f1de772d0203321693202dfdd742fa82bba12428 | |
parent | d88473bc53f32a54f18d976a97cc4d39f8902848 (diff) | |
download | libical-git-acf1ae1dacb43f967b289e0922856703c1e15d1f.tar.gz |
time_t - replace type `time_t` and related functions with our own `icaltime_t`, etc. and define it centrally in `config_public.h.cmake` and `config.h.cmake`. This allows for easy replacement, should the system-defined time_t not be suitable. This might especially be the case on 32-bit systems where the range of time_t ends 2038.
-rw-r--r-- | config.h.cmake | 13 | ||||
-rw-r--r-- | config_public.h.cmake | 4 | ||||
-rw-r--r-- | doc/UsingLibical.md | 8 | ||||
-rw-r--r-- | src/libical/icalcomponent.c | 10 | ||||
-rw-r--r-- | src/libical/icalderivedproperty.h.in | 1 | ||||
-rw-r--r-- | src/libical/icalduration.c | 4 | ||||
-rw-r--r-- | src/libical/icalrecur.c | 12 | ||||
-rw-r--r-- | src/libical/icalrecur.h | 6 | ||||
-rw-r--r-- | src/libical/icaltime.c | 50 | ||||
-rw-r--r-- | src/libical/icaltime.h | 16 | ||||
-rw-r--r-- | src/libical/icaltimezone.c | 10 | ||||
-rw-r--r-- | src/libical/icaltz-util.c | 20 | ||||
-rw-r--r-- | src/libicalss/icalspanlist.c | 16 | ||||
-rw-r--r-- | src/libicalvcal/icalvcal.c | 10 | ||||
-rw-r--r-- | src/test/recur.c | 2 | ||||
-rw-r--r-- | src/test/regression-component.c | 6 | ||||
-rw-r--r-- | src/test/regression-recur.c | 2 | ||||
-rw-r--r-- | src/test/regression-utils.c | 6 | ||||
-rw-r--r-- | src/test/regression.c | 30 | ||||
-rw-r--r-- | src/test/regression.h | 2 | ||||
-rw-r--r-- | src/test/timezones.c | 8 |
21 files changed, 125 insertions, 111 deletions
diff --git a/config.h.cmake b/config.h.cmake index aae1cf8a..561b91a8 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -522,7 +522,18 @@ typedef ssize_t IO_SSIZE_T; /* FYI: The localtime() in Microsoft's C library is MT-safe */ #define localtime_r(tp,tmp) (localtime(tp)?(*(tmp)=*localtime(tp),(tmp)):0) #endif -#include <time.h> + +#define SIZEOF_ICALTIME_T SIZEOF_TIME_T + +/* + * Substitute functions for those from time.h but working with icaltime_t instead of time_t. + * icaltime_t is defined in config_public.h.cmake. + */ +#define icaltime(timer) time(timer) +#define icalctime(timer) ctime(timer) +#define icalmktime(timeptr) mktime(timeptr) +#define icalgmtime_r(timer, buf) gmtime_r(timer, buf) +#define icallocaltime_r(timer, buf) localtime_r(timer, buf) /* define MAXPATHLEN */ #if defined(_WIN32) diff --git a/config_public.h.cmake b/config_public.h.cmake index d6dd111c..2cffaced 100644 --- a/config_public.h.cmake +++ b/config_public.h.cmake @@ -1 +1,5 @@ /* config_public.h. Generated by cmake from config_public.h.cmake */
+
+#include <time.h>
+
+typedef time_t icaltime_t;
diff --git a/doc/UsingLibical.md b/doc/UsingLibical.md index 12fb9bcc..4d3b80e3 100644 --- a/doc/UsingLibical.md +++ b/doc/UsingLibical.md @@ -876,7 +876,7 @@ struct icaltimetype icaltime_from_string( const char* str); struct icaltimetype icaltime_from_timet_with_zone( - time_t v, + icaltime_t v, int is_date, icaltimezone* zone); ``` @@ -887,7 +887,7 @@ struct icaltimetype icaltime_from_timet_with_zone( struct icaltimetype tt = icaltime_from_string("19970101T103000"); ``` -`icaltime_from_timet_with_zone()` takes a `time_t` value, representing seconds past +`icaltime_from_timet_with_zone()` takes a `icaltime_t` value, representing seconds past the POSIX epoch, a flag to indicate if the time is a date, and a time zone. Dates have an identical structure to a time, but the time portion (hours, minutes and seconds) is always 00:00:00. Dates act differently in @@ -960,11 +960,11 @@ the hour, minute and second fields should be used in the conversion. ```c struct icaltimetype icaltime_from_timet_with_zone( - time_t v, + icaltime_t v, int is_date, icaltimezone* zone); -time_t icaltime_as_timet( +icaltime_t icaltime_as_timet( struct icaltimetype); ``` diff --git a/src/libical/icalcomponent.c b/src/libical/icalcomponent.c index 0207fa70..bc179b73 100644 --- a/src/libical/icalcomponent.c +++ b/src/libical/icalcomponent.c @@ -871,8 +871,8 @@ void icalcomponent_foreach_recurrence(icalcomponent *comp, { struct icaltimetype dtstart, dtend; icaltime_span recurspan, basespan, limit_span; - time_t limit_start, limit_end; - time_t dtduration; + icaltime_t limit_start, limit_end; + icaltime_t dtduration; icalproperty *rrule, *rdate; pvl_elem property_iterator; /* for saving the iterator */ @@ -906,10 +906,10 @@ void icalcomponent_foreach_recurrence(icalcomponent *comp, limit_end = icaltime_as_timet_with_zone(end, icaltimezone_get_utc_timezone()); } else { -#if (SIZEOF_TIME_T > 4) - limit_end = (time_t) LONG_MAX; +#if (SIZEOF_ICALTIME_T > 4) + limit_end = (icaltime_t) LONG_MAX; #else - limit_end = (time_t) INT_MAX; + limit_end = (icaltime_t) INT_MAX; #endif } limit_span.start = limit_start; diff --git a/src/libical/icalderivedproperty.h.in b/src/libical/icalderivedproperty.h.in index 0ebec067..034cfe1b 100644 --- a/src/libical/icalderivedproperty.h.in +++ b/src/libical/icalderivedproperty.h.in @@ -19,7 +19,6 @@ #ifndef ICALDERIVEDPROPERTY_H #define ICALDERIVEDPROPERTY_H -#include <time.h> #include "icalparameter.h" #include "icalderivedvalue.h" #include "icalrecur.h" diff --git a/src/libical/icalduration.c b/src/libical/icalduration.c index c978fb79..79789d97 100644 --- a/src/libical/icalduration.c +++ b/src/libical/icalduration.c @@ -338,8 +338,8 @@ struct icaltimetype icaltime_add(struct icaltimetype t, struct icaldurationtype struct icaldurationtype icaltime_subtract(struct icaltimetype t1, struct icaltimetype t2) { - time_t t1t = icaltime_as_timet(t1); - time_t t2t = icaltime_as_timet(t2); + icaltime_t t1t = icaltime_as_timet(t1); + icaltime_t t2t = icaltime_as_timet(t2); return icaldurationtype_from_int((int)(t1t - t2t)); } diff --git a/src/libical/icalrecur.c b/src/libical/icalrecur.c index 886fd75b..c41e258d 100644 --- a/src/libical/icalrecur.c +++ b/src/libical/icalrecur.c @@ -169,12 +169,12 @@ static ical_invalid_rrule_handling invalidRruleHandling = ICAL_RRULE_TREAT_AS_ER #define ICAL_BY_YEARDAY_SIZE 367 /* 1 to 366 */ #endif -#if (SIZEOF_TIME_T > 4) +#if (SIZEOF_ICALTIME_T > 4) /** Arbitrarily go up to 1000th anniversary of Gregorian calendar, since - 64-bit time_t values get us up to the tm_year limit of 2+ billion years. */ + 64-bit icaltime_t values get us up to the tm_year limit of 2+ billion years. */ #define MAX_TIME_T_YEAR 2582 #else -/** This is the last year we will go up to, since 32-bit time_t values +/** This is the last year we will go up to, since 32-bit icaltime_t values only go up to the start of 2038. */ #define MAX_TIME_T_YEAR 2037 #endif @@ -3613,15 +3613,15 @@ short icalrecurrencetype_encode_month(int month, int is_leap) } int icalrecur_expand_recurrence(const char *rule, - time_t start, int count, time_t *array) + icaltime_t start, int count, icaltime_t*array) { struct icalrecurrencetype recur; icalrecur_iterator *ritr; - time_t tt; + icaltime_t tt; struct icaltimetype icstart, next; int i = 0; - memset(array, 0, count * sizeof(time_t)); + memset(array, 0, count * sizeof(icaltime_t)); icstart = icaltime_from_timet_with_zone(start, 0, 0); diff --git a/src/libical/icalrecur.h b/src/libical/icalrecur.h index f7fe5ce4..98e74a75 100644 --- a/src/libical/icalrecur.h +++ b/src/libical/icalrecur.h @@ -359,15 +359,15 @@ LIBICAL_ICAL_EXPORT void icalrecur_iterator_free(icalrecur_iterator *); /** @brief Fills an array with the 'count' number of occurrences generated by * the rrule. * - * Specifically, this fills @p array up with at most 'count' time_t values, each + * Specifically, this fills @p array up with at most 'count' icaltime_t values, each * representing an occurrence time in seconds past the POSIX epoch. * * Note that the times are returned in UTC, but the times * are calculated in local time. You will have to convert the results * back into local time before using them. */ -LIBICAL_ICAL_EXPORT int icalrecur_expand_recurrence(const char *rule, time_t start, - int count, time_t *array); +LIBICAL_ICAL_EXPORT int icalrecur_expand_recurrence(const char *rule, icaltime_t start, + int count, icaltime_t*array); /* ical_invalid_rrule_handling : * How should the ICAL library handle RRULEs with invalid BYxxx part combos? diff --git a/src/libical/icaltime.c b/src/libical/icaltime.c index 33209508..8e77cc4b 100644 --- a/src/libical/icaltime.c +++ b/src/libical/icaltime.c @@ -77,16 +77,16 @@ static int icaltime_leap_days(int y1, int y2) /* * Code adapted from Python 2.4.1 sources (Lib/calendar.py). */ -static time_t icaltime_timegm(const struct tm *tm) +static icaltime_t icaltime_timegm(const struct tm *tm) { int year; - time_t days; - time_t hours; - time_t minutes; - time_t seconds; + icaltime_t days; + icaltime_t hours; + icaltime_t minutes; + icaltime_t seconds; year = 1900 + tm->tm_year; - days = (time_t)(365 * (year - 1970) + icaltime_leap_days(1970, year)); + days = (icaltime_t)(365 * (year - 1970) + icaltime_leap_days(1970, year)); days += days_in_year_passed_month[0][tm->tm_mon]; if (tm->tm_mon > 1 && icaltime_is_leap_year(year)) @@ -102,40 +102,40 @@ static time_t icaltime_timegm(const struct tm *tm) /* * Function to convert a struct tm time specification - * to an ANSI time_t using the specified time zone. + * to an ANSI-compatible icaltime_t using the specified time zone. * This is different from the standard mktime() function * in that we don't want the automatic adjustments for * local daylight savings time applied to the result. * This function expects well-formed input. */ -static time_t make_time(struct tm *tm, int tzm) +static icaltime_t make_time(struct tm *tm, int tzm) { - time_t tim; + icaltime_t tim; static int days[] = { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 }; /* check that month specification within range */ if (tm->tm_mon < 0 || tm->tm_mon > 11) - return ((time_t) - 1); + return ((icaltime_t) - 1); -#if (SIZEOF_TIME_T == 4) +#if (SIZEOF_ICALTIME_T == 4) /* check that year specification within range */ if (tm->tm_year < 70 || tm->tm_year > 138) - return ((time_t) - 1); + return ((icaltime_t) - 1); /* check for upper bound of Jan 17, 2038 (to avoid possibility of 32-bit arithmetic overflow) */ if (tm->tm_year == 138) { if (tm->tm_mon > 0) { - return ((time_t) - 1); + return ((icaltime_t) - 1); } else if (tm->tm_mday > 17) { - return ((time_t) - 1); + return ((icaltime_t) - 1); } } -#endif /* SIZEOF_TIME_T */ +#endif /* SIZEOF_ICALTIME_T */ /* * calculate elapsed days since start of the epoch (midnight Jan @@ -143,7 +143,7 @@ static time_t make_time(struct tm *tm, int tzm) * (number of leap days to subtract) */ - tim = (time_t) ((tm->tm_year - 70) * 365 + ((tm->tm_year - 1) / 4) - 17); + tim = (icaltime_t) ((tm->tm_year - 70) * 365 + ((tm->tm_year - 1) / 4) - 17); /* add number of days elapsed in the current year */ @@ -180,7 +180,7 @@ static time_t make_time(struct tm *tm, int tzm) return (tim); } -struct icaltimetype icaltime_from_timet_with_zone(const time_t tm, const int is_date, +struct icaltimetype icaltime_from_timet_with_zone(const icaltime_t tm, const int is_date, const icaltimezone *zone) { struct icaltimetype tt; @@ -189,8 +189,8 @@ struct icaltimetype icaltime_from_timet_with_zone(const time_t tm, const int is_ utc_zone = icaltimezone_get_utc_timezone(); - /* Convert the time_t to a struct tm in UTC time. We can trust gmtime for this. */ - if (!gmtime_r(&tm, &t)) + /* Convert the icaltime_t to a struct tm in UTC time. We can trust gmtime for this. */ + if (!icalgmtime_r(&tm, &t)) return is_date ? icaltime_null_date () : icaltime_null_time (); tt.year = t.tm_year + 1900; @@ -220,18 +220,18 @@ struct icaltimetype icaltime_from_timet_with_zone(const time_t tm, const int is_ struct icaltimetype icaltime_current_time_with_zone(const icaltimezone *zone) { - return icaltime_from_timet_with_zone(time(NULL), 0, zone); + return icaltime_from_timet_with_zone(icaltime(NULL), 0, zone); } struct icaltimetype icaltime_today(void) { - return icaltime_from_timet_with_zone(time(NULL), 1, NULL); + return icaltime_from_timet_with_zone(icaltime(NULL), 1, NULL); } -time_t icaltime_as_timet(const struct icaltimetype tt) +icaltime_t icaltime_as_timet(const struct icaltimetype tt) { struct tm stm; - time_t t; + icaltime_t t; /* If the time is the special null time, return 0. */ if (icaltime_is_null_time(tt)) { @@ -259,11 +259,11 @@ time_t icaltime_as_timet(const struct icaltimetype tt) return t; } -time_t icaltime_as_timet_with_zone(const struct icaltimetype tt, const icaltimezone *zone) +icaltime_t icaltime_as_timet_with_zone(const struct icaltimetype tt, const icaltimezone *zone) { icaltimezone *utc_zone; struct tm stm; - time_t t; + icaltime_t t; struct icaltimetype local_tt; utc_zone = icaltimezone_get_utc_timezone(); diff --git a/src/libical/icaltime.h b/src/libical/icaltime.h index 1e28492b..c663ba2e 100644 --- a/src/libical/icaltime.h +++ b/src/libical/icaltime.h @@ -37,7 +37,7 @@ * - icaltime_null_date() * - icaltime_current_time_with_zone() * - icaltime_today() - * - icaltime_from_timet_with_zone(time_t tm, int is_date, + * - icaltime_from_timet_with_zone(icaltime_t tm, int is_date, * icaltimezone *zone) * - icaltime_from_day_of_year(int doy, int year) * @@ -82,7 +82,7 @@ #include "libical_ical_export.h" -#include <time.h> +#include "config_public.h" /* An opaque struct representing a timezone. We declare this here to avoid a circular dependency. */ @@ -94,8 +94,8 @@ typedef struct _icaltimezone icaltimezone; /** icaltime_span is returned by icalcomponent_get_span() */ struct icaltime_span { - time_t start; /**< in UTC */ - time_t end; /**< in UTC */ + icaltime_t start; /**< in UTC */ + icaltime_t end; /**< in UTC */ int is_busy; /**< 1->busy time, 0-> free time */ }; @@ -169,7 +169,7 @@ LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_today(void); * target timezone with no need to store the source timezone. * */ -LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_from_timet_with_zone(const time_t tm, +LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_from_timet_with_zone(const icaltime_t tm, const int is_date, const icaltimezone *zone); @@ -199,7 +199,7 @@ LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_from_day_of_year(const int doy, * only pass an icaltime in UTC, since no conversion is done. Even in that case, * it's probably better to just use icaltime_as_timet_with_zone(). */ -LIBICAL_ICAL_EXPORT time_t icaltime_as_timet(const struct icaltimetype); +LIBICAL_ICAL_EXPORT icaltime_t icaltime_as_timet(const struct icaltimetype); /** @brief Returns the time as seconds past the UNIX epoch, using the * given timezone. @@ -207,9 +207,9 @@ LIBICAL_ICAL_EXPORT time_t icaltime_as_timet(const struct icaltimetype); * This convenience method combines a call to icaltime_convert_to_zone() * with a call to icaltime_as_timet(). * If the input timezone is null, no conversion is done; that is, the - * time is simply returned as time_t in its native timezone. + * time is simply returned as icaltime_t in its native timezone. */ -LIBICAL_ICAL_EXPORT time_t icaltime_as_timet_with_zone(const struct icaltimetype tt, +LIBICAL_ICAL_EXPORT icaltime_t icaltime_as_timet_with_zone(const struct icaltimetype tt, const icaltimezone *zone); /** diff --git a/src/libical/icaltimezone.c b/src/libical/icaltimezone.c index ba581dc0..4fc46c99 100644 --- a/src/libical/icaltimezone.c +++ b/src/libical/icaltimezone.c @@ -85,12 +85,12 @@ static char s_ical_tzid_prefix[BUILTIN_TZID_PREFIX_LEN] = {0}; the timezone changes. */ #define ICALTIMEZONE_EXTRA_COVERAGE 5 -#if (SIZEOF_TIME_T > 4) +#if (SIZEOF_ICALTIME_T > 4) /** Arbitrarily go up to 1000th anniversary of Gregorian calendar, since - 64-bit time_t values get us up to the tm_year limit of 2+ billion years. */ + 64-bit icaltime_t values get us up to the tm_year limit of 2+ billion years. */ #define ICALTIMEZONE_MAX_YEAR 2582 #else -/** This is the maximum year we will expand to, since 32-bit time_t values +/** This is the maximum year we will expand to, since 32-bit icaltime_t values only go up to the start of 2038. */ #define ICALTIMEZONE_MAX_YEAR 2037 #endif @@ -1431,9 +1431,9 @@ static int get_offset(icaltimezone *zone) struct tm local; struct icaltimetype tt; int offset; - const time_t now = time(NULL); + const icaltime_t now = icaltime(NULL); - if (!gmtime_r(&now, &local)) + if (!icalgmtime_r(&now, &local)) return 0; tt = tm_to_icaltimetype(&local); diff --git a/src/libical/icaltz-util.c b/src/libical/icaltz-util.c index ec096c19..8abae608 100644 --- a/src/libical/icaltz-util.c +++ b/src/libical/icaltz-util.c @@ -127,7 +127,7 @@ typedef struct typedef struct { - time_t transition; + icaltime_t transition; long int change; } leap; //@endcond @@ -445,7 +445,7 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) const char *zonedir; FILE *f = NULL; char *full_path = NULL; - time_t *transitions = NULL; + icaltime_t*transitions = NULL; char *r_trans = NULL, *temp; int *trans_idx = NULL; ttinfo *types = NULL; @@ -507,7 +507,7 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) break; case '2': case '3': - if (sizeof(time_t) == 8) { + if (sizeof(icaltime_t) == 8) { trans_size = 8; } break; @@ -549,7 +549,7 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) } /* read data block */ - transitions = icalmemory_new_buffer((num_trans+1) * sizeof(time_t)); // +1 for TZ string + transitions = icalmemory_new_buffer((num_trans+1) * sizeof(icaltime_t)); // +1 for TZ string if (transitions == NULL) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); goto error; @@ -566,7 +566,7 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) } if (num_trans == 0) { // Add one transition using time type 0 at 19011213T204552Z - transitions[0] = (time_t)INT_MIN; + transitions[0] = (icaltime_t)INT_MIN; trans_idx[0] = 0; num_trans = 1; } else { @@ -575,9 +575,9 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) for (i = 0; i < num_trans; i++) { trans_idx[i] = fgetc(f); if (trans_size == 8) { - transitions[i] = (time_t) decode64(r_trans); + transitions[i] = (icaltime_t) decode64(r_trans); } else { - transitions[i] = (time_t) decode(r_trans); + transitions[i] = (icaltime_t) decode(r_trans); } r_trans += trans_size; } @@ -622,9 +622,9 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) EFREAD(c, (size_t)trans_size, 1, f); if (trans_size == 8) { - leaps[i].transition = (time_t)decode64(c); + leaps[i].transition = (icaltime_t)decode64(c); } else { - leaps[i].transition = (time_t)decode(c); + leaps[i].transition = (icaltime_t)decode(c); } EFREAD(c, 4, 1, f); @@ -757,7 +757,7 @@ icalcomponent *icaltzutil_fetch_timezone(const char *location) for (i = 0; i < num_trans; i++) { int by_day = 0; - time_t start; + icaltime_t start; enum icalrecurrencetype_weekday dow; prev_idx = idx; diff --git a/src/libicalss/icalspanlist.c b/src/libicalss/icalspanlist.c index a0f40ef6..6b042b12 100644 --- a/src/libicalss/icalspanlist.c +++ b/src/libicalss/icalspanlist.c @@ -229,7 +229,7 @@ struct icalperiodtype icalspanlist_next_free_time(icalspanlist *sl, struct icalt struct icalperiodtype period; struct icaltime_span *s; - time_t rangett = icaltime_as_timet(t); + icaltime_t rangett = icaltime_as_timet(t); period.start = icaltime_null_time(); period.end = icaltime_null_time(); @@ -290,17 +290,17 @@ struct icalperiodtype icalspanlist_next_free_time(icalspanlist *sl, struct icalt int *icalspanlist_as_freebusy_matrix(icalspanlist *sl, int delta_t) { pvl_elem itr; - time_t spanduration_secs; + icaltime_t spanduration_secs; int *matrix; - time_t matrix_slots; - time_t sl_start, sl_end; + icaltime_t matrix_slots; + icaltime_t sl_start, sl_end; icalerror_check_arg_rz((sl != 0), "spanlist"); if (!delta_t) delta_t = 3600; - /* calculate the start and end time as time_t **/ + /* calculate the start and end time as icaltime_t **/ sl_start = icaltime_as_timet_with_zone(sl->start, icaltimezone_get_utc_timezone()); sl_end = icaltime_as_timet_with_zone(sl->end, icaltimezone_get_utc_timezone()); @@ -333,9 +333,9 @@ int *icalspanlist_as_freebusy_matrix(icalspanlist *sl, int delta_t) struct icaltime_span *s = (struct icaltime_span *)pvl_data(itr); if (s && s->is_busy == 1) { - time_t offset_start = s->start / delta_t - sl_start / delta_t; - time_t offset_end = (s->end - 1) / delta_t - sl_start / delta_t + 1; - time_t i; + icaltime_t offset_start = s->start / delta_t - sl_start / delta_t; + icaltime_t offset_end = (s->end - 1) / delta_t - sl_start / delta_t + 1; + icaltime_t i; if (offset_end >= matrix_slots) offset_end = matrix_slots - 1; diff --git a/src/libicalvcal/icalvcal.c b/src/libicalvcal/icalvcal.c index a4389603..29b3c1bf 100644 --- a/src/libicalvcal/icalvcal.c +++ b/src/libicalvcal/icalvcal.c @@ -118,11 +118,11 @@ static const char *get_string_value(VObject *object, int *free_string) static void convert_floating_time_to_utc(struct icaltimetype *itt) { struct tm tmp_tm, utc_tm; - time_t t; + icaltime_t t; /* We assume the floating time is using the current Unix timezone. - So we convert to a time_t using mktime(), and then back to a struct tm - using gmtime, so it is the UTC time. */ + So we convert to a icaltime_t using icalmktime(), and then back to a struct tm + using icalgmtime_r, so it is the UTC time. */ tmp_tm.tm_year = itt->year - 1900; tmp_tm.tm_mon = itt->month - 1; tmp_tm.tm_mday = itt->day; @@ -131,11 +131,11 @@ static void convert_floating_time_to_utc(struct icaltimetype *itt) tmp_tm.tm_sec = itt->second; tmp_tm.tm_isdst = -1; - /* Convert to a time_t. */ + /* Convert to a icaltime_t. */ t = mktime(&tmp_tm); /* Now convert back to a struct tm, but with a UTC time. */ - if (!gmtime_r(&t, &utc_tm)) { + if (!icalgmtime_r(&t, &utc_tm)) { *itt = itt->is_date ? icaltime_null_date () : icaltime_null_time (); return; } diff --git a/src/test/recur.c b/src/test/recur.c index 01552802..e776763f 100644 --- a/src/test/recur.c +++ b/src/test/recur.c @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) icalproperty *desc, *dtstart, *rrule; struct icalrecurrencetype recur; icalrecur_iterator *ritr; - time_t tt; + icaltime_t tt; const char *file; icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); diff --git a/src/test/regression-component.c b/src/test/regression-component.c index caed9af4..9366ccdc 100644 --- a/src/test/regression-component.c +++ b/src/test/regression-component.c @@ -310,9 +310,9 @@ static void print_span(int c, struct icaltime_span span) */ void test_icalcomponent_get_span() { - time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, + icaltime_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, Sat Nov 4 15:00:00 PST 2000 */ - time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 + icaltime_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 Sat Nov 4 16:00:00 PST 2000 */ struct icaldurationtype dur; struct icaltime_span span; @@ -321,7 +321,7 @@ void test_icalcomponent_get_span() int tnum = 0; /** test 0 - * Direct assigning time_t means they will be interpreted as UTC + * Direct assigning icaltime_t means they will be interpreted as UTC */ span.start = tm1; span.end = tm2; diff --git a/src/test/regression-recur.c b/src/test/regression-recur.c index e11112e6..d25052d8 100644 --- a/src/test/regression-recur.c +++ b/src/test/regression-recur.c @@ -83,7 +83,7 @@ void test_recur_file() icalproperty *desc, *dtstart, *rrule; struct icalrecurrencetype recur; icalrecur_iterator *ritr; - time_t tt; + icaltime_t tt; const char *file; int num_recurs_found = 0; icalfileset_options options = { O_RDONLY, 0644, 0, NULL }; diff --git a/src/test/regression-utils.c b/src/test/regression-utils.c index 9987a640..937a808d 100644 --- a/src/test/regression-utils.c +++ b/src/test/regression-utils.c @@ -33,12 +33,12 @@ int VERBOSE = 1; static char ictt_str[1024]; -const char *ical_timet_string(const time_t t) +const char *ical_timet_string(const icaltime_t t) { struct tm tmp, stm; memset(&tmp, 0, sizeof(tmp)); - if (gmtime_r(&t, &tmp)) { + if (icalgmtime_r(&t, &tmp)) { stm = tmp; } else { memset(&stm, 0, sizeof(stm)); @@ -71,7 +71,7 @@ const char *ictt_as_string(struct icaltimetype t) char *icaltime_as_ctime(struct icaltimetype t) { - time_t tt; + icaltime_t tt; tt = icaltime_as_timet(t); snprintf(ictt_str, sizeof(ictt_str), "%s", ctime(&tt)); diff --git a/src/test/regression.c b/src/test/regression.c index b32bc37b..1bf0837b 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -1226,7 +1226,7 @@ void print_occur(struct icalrecurrencetype recur, struct icaltimetype start) struct icaltimetype next; icalrecur_iterator *ritr; - time_t tt = icaltime_as_timet(start); + icaltime_t tt = icaltime_as_timet(start); printf("#### %s\n", icalrecurrencetype_as_string(&recur)); printf("#### %s\n", ctime(&tt)); @@ -1246,7 +1246,7 @@ void test_recur() { struct icalrecurrencetype rt; struct icaltimetype start; - time_t array[25]; + icaltime_t array[25]; int i; rt = icalrecurrencetype_from_string( @@ -1359,8 +1359,8 @@ void test_recur_encode_by_month() void test_expand_recurrence() { - time_t arr[10]; - time_t now = 931057385; + icaltime_t arr[10]; + icaltime_t now = 931057385; int i, numfound = 0; icalrecur_expand_recurrence("FREQ=MONTHLY;BYDAY=MO,WE", now, 5, arr); @@ -1400,7 +1400,7 @@ void icalrecurrencetype_test() struct icalrecurrencetype r = icalvalue_get_recur(v); struct icaltimetype t = icaltime_from_timet_with_zone(time(0), 0, NULL); struct icaltimetype next; - time_t tt; + icaltime_t tt; struct icalrecur_iterator_impl *itr = (struct icalrecur_iterator_impl *)icalrecur_iterator_new(r, t); @@ -1776,8 +1776,8 @@ void do_test_time(const char *zone) { struct icaltimetype ictt, icttutc, icttzone, icttdayl, icttla, icttny, icttphoenix, icttlocal, icttnorm; - time_t tt, tt2, tt_p200; - time_t offset_tz; + icaltime_t tt, tt2, tt_p200; + icaltime_t offset_tz; icalvalue *v; short day_of_week, start_day_of_week, day_of_year; icaltimezone *azone, *utczone; @@ -1790,7 +1790,7 @@ void do_test_time(const char *zone) /* Test new API */ if (VERBOSE) { - printf("\n---> From time_t \n"); + printf("\n---> From icaltime_t \n"); } tt = 1025127869; /* stick with a constant... Wed, 26 Jun 2002 21:44:29 GMT */ @@ -1800,7 +1800,7 @@ void do_test_time(const char *zone) } ictt = icaltime_from_timet_with_zone(tt, 0, NULL); - str_is("Floating time from time_t", ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)"); + str_is("Floating time from icaltime_t", ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)"); ictt = icaltime_from_timet_with_zone(tt, 0, azone); #if ADD_TESTS_REQUIRING_INVESTIGATION @@ -1878,7 +1878,7 @@ void do_test_time(const char *zone) tt = icaltime_as_timet(ictt); - ok("test icaltime -> time_t for 20001103T183030Z", (tt == 973276230)); + ok("test icaltime -> icaltime_t for 20001103T183030Z", (tt == 973276230)); /* Fri Nov 3 10:30:30 PST 2000 in PST Fri Nov 3 18:30:30 PST 2000 in UTC */ @@ -1903,7 +1903,7 @@ void do_test_time(const char *zone) /** add test case here.. **/ if (VERBOSE) { - printf("\n As time_t \n"); + printf("\n As icaltime_t \n"); } tt2 = icaltime_as_timet(ictt); @@ -1923,7 +1923,7 @@ void do_test_time(const char *zone) printf("20001103T183030 : %s\n", ictt_as_string(icttlocal)); } - offset_tz = (time_t) (-icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0)); + offset_tz = (icaltime_t) (-icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0)); if (VERBOSE) printf("offset_tz : %ld\n", (long)offset_tz); @@ -2279,12 +2279,12 @@ void test_overlaps() { icalcomponent *cset, *c; icalset *set; - time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, + icaltime_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, Sat Nov 4 15:00:00 PST 2000 */ - time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 + icaltime_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 Sat Nov 4 16:00:00 PST 2000 */ - time_t hh = 1800; /* one half hour */ + icaltime_t hh = 1800; /* one half hour */ icalfileset_options options = { O_RDONLY, 0644, 0, NULL }; set = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/overlaps.ics", &options); diff --git a/src/test/regression.h b/src/test/regression.h index 9c5aab88..100dab00 100644 --- a/src/test/regression.h +++ b/src/test/regression.h @@ -52,7 +52,7 @@ extern "C" void test_bdbset(void); /* regression-utils.c */ - const char *ical_timet_string(const time_t t); + const char *ical_timet_string(const icaltime_t t); const char *ictt_as_string(struct icaltimetype t); char *icaltime_as_ctime(struct icaltimetype t); diff --git a/src/test/timezones.c b/src/test/timezones.c index 935e912d..6491f6fc 100644 --- a/src/test/timezones.c +++ b/src/test/timezones.c @@ -39,9 +39,9 @@ int main() int verbose = 0; int day; - time_t start_time; + icaltime_t start_time; struct tm start_tm; - time_t curr_time; + icaltime_t curr_time; struct tm curr_tm; struct icaltimetype curr_tt; int failed = 0; @@ -82,7 +82,7 @@ int main() * determine current local time and date: always use midday in * the current zone and first day of first month in the year */ - start_time = time(NULL); + start_time = icaltime(NULL); (void)localtime_r(&start_time, &start_tm); start_tm.tm_hour = 12; start_tm.tm_min = 0; @@ -114,7 +114,7 @@ int main() if (verbose || curr_failed != failed) { struct tm utc_tm; - if (!gmtime_r(&curr_time, &utc_tm)) + if (!icalgmtime_r(&curr_time, &utc_tm)) memset(&utc_tm, 0, sizeof(utc_tm)); printf( |