From a8b82e22f5f615718d726335fb28eee4513365f7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 5 Oct 2004 01:59:32 +0000 Subject: [PATCH] * localtime_r() fixes --- webcit/ChangeLog | 4 +++- webcit/calendar_tools.c | 8 ++++---- webcit/calendar_view.c | 26 +++++++++++++------------- webcit/event.c | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 50fe89747..0ac846ef0 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 524.4 2004/10/05 01:59:31 ajc +* localtime_r() fixes + Revision 524.3 2004/10/03 02:56:35 ajc * Added a pthread_attr_destroy() in the appropriate place (thanks fleeb!) @@ -2090,4 +2093,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c index bea5fc109..5b34a88c1 100644 --- a/webcit/calendar_tools.c +++ b/webcit/calendar_tools.c @@ -74,17 +74,17 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { int all_day_event = 0; now = time(NULL); - memcpy(&tm_now, localtime(&now), sizeof(struct tm)); + localtime_r(&now, &tm_now); this_year = tm_now.tm_year + 1900; if (t == NULL) return; if (t->is_date) all_day_event = 1; tt = icaltime_as_timet(*t); if (all_day_event) { - memcpy(&tm, gmtime(&tt), sizeof(struct tm)); + gmtime_r(&tt, &tm); } else { - memcpy(&tm, localtime(&tt), sizeof(struct tm)); + localtime_r(&tt, &tm); } wprintf("Month: "); @@ -157,7 +157,7 @@ struct icaltimetype icaltime_from_webform(char *prefix) { char vname[SIZ]; tt = time(NULL); - memcpy(&tm, localtime(&tt), sizeof(struct tm)); + localtime_r(&tt, &tm); sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1; sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname)); diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 42829f9ab..d89af8631 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -56,7 +56,7 @@ void calendar_month_view_display_events(time_t thetime) { return; } - memcpy(&today_tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &today_tm); month = today_tm.tm_mon + 1; day = today_tm.tm_mday; year = today_tm.tm_year + 1900; @@ -72,10 +72,10 @@ void calendar_month_view_display_events(time_t thetime) { else all_day_event = 0; if (all_day_event) { - memcpy(&event_tm, gmtime(&event_tt), sizeof(struct tm)); + gmtime_r(&event_tt, &event_tm); } else { - memcpy(&event_tm, localtime(&event_tt), sizeof(struct tm)); + localtime_r(&event_tt, &event_tm); } lprintf(9, "Event: %04d/%02d/%02d, Now: %04d/%02d/%02d\n", @@ -149,7 +149,7 @@ void calendar_month_view(int year, int month, int day) { memcpy(&tm, &starting_tm, sizeof(struct tm)); while (tm.tm_mday != 1) { thetime = thetime - (time_t)86400; /* go back 24 hours */ - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); } /* Determine previous and next months ... for links */ @@ -157,10 +157,10 @@ void calendar_month_view(int year, int month, int day) { next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */ /* Now back up until we're on a Sunday */ - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); while (tm.tm_wday != 0) { thetime = thetime - (time_t)86400; /* go back 24 hours */ - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); } /* Outer table (to get the background color) */ @@ -178,7 +178,7 @@ void calendar_month_view(int year, int month, int day) { wprintf(""); - memcpy(&tm, localtime(&previous_month), sizeof(struct tm)); + localtime_r(&previous_month, &tm); wprintf("", (int)(tm.tm_year)+1900, tm.tm_mon + 1); wprintf("\n"); @@ -189,7 +189,7 @@ void calendar_month_view(int year, int month, int day) { "" "  ", months[month-1], year); - memcpy(&tm, localtime(&next_month), sizeof(struct tm)); + localtime_r(&next_month, &tm); wprintf("", (int)(tm.tm_year)+1900, tm.tm_mon + 1); wprintf("\n"); @@ -209,7 +209,7 @@ void calendar_month_view(int year, int month, int day) { /* Now do 35 days */ for (i = 0; i < 35; ++i) { - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); /* Before displaying Sunday, start a new row */ if ((i % 7) == 0) { @@ -485,7 +485,7 @@ void calendar_summary_view(void) { } now = time(NULL); - memcpy(&today_tm, localtime(&now), sizeof(struct tm)); + localtime_r(&now, &today_tm); for (i=0; i<(WC->num_cal); ++i) { p = icalcomponent_get_first_property(WC->disp_cal[i].cal, @@ -497,10 +497,10 @@ void calendar_summary_view(void) { fmt_time(timestring, event_tt); if (all_day_event) { - memcpy(&event_tm, gmtime(&event_tt), sizeof(struct tm)); + gmtime_r(&event_tt, &event_tm); } else { - memcpy(&event_tm, localtime(&event_tt), sizeof(struct tm)); + localtime_r(&event_tt, &event_tm); } if ( (event_tm.tm_year == today_tm.tm_year) @@ -546,7 +546,7 @@ void do_calendar_view(void) { /* In case no date was specified, go with today */ now = time(NULL); - memcpy(&tm, localtime(&now), sizeof(struct tm)); + localtime_r(&now, &tm); year = tm.tm_year + 1900; month = tm.tm_mon + 1; day = tm.tm_mday; diff --git a/webcit/event.c b/webcit/event.c index d7ed702a6..8f99da03a 100644 --- a/webcit/event.c +++ b/webcit/event.c @@ -145,7 +145,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) } } else { - memcpy(&tm_now, localtime(&now), sizeof(struct tm)); + localtime_r(&now, &tm_now); tm_now.tm_year = atoi(bstr("year")) - 1900; tm_now.tm_mon = atoi(bstr("month")) - 1; tm_now.tm_mday = atoi(bstr("day")); -- 2.30.2