summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2010-07-23 09:11:11 +0000
committerRay Lai <ray@cvs.openbsd.org>2010-07-23 09:11:11 +0000
commit6aacbaff87507b9a7763028157d45771d927dd79 (patch)
treeb3e26fd2b17fd272eedb0c94c4fe6f339729c6b3 /usr.bin
parent8b3cb0e63b473ff2e2cdcb8d71dd7821a9543e4e (diff)
Clean up struct tm handling. Instead of calling gmtime/localtime
and making copies (among other weird dances), use reentrant versions. Not being able to tell the time is a fatal error, so die if that happens. Diff originally from nicm. OK nicm xsa
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/date.y45
1 files changed, 15 insertions, 30 deletions
diff --git a/usr.bin/cvs/date.y b/usr.bin/cvs/date.y
index 6e30f6e4f6e..93da8115e54 100644
--- a/usr.bin/cvs/date.y
+++ b/usr.bin/cvs/date.y
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: date.y,v 1.18 2008/02/16 01:00:00 cnst Exp $ */
+/* $OpenBSD: date.y,v 1.19 2010/07/23 09:11:10 ray Exp $ */
/*
** Originally written by Steven M. Bellovin <smb@research.att.com> while
@@ -807,39 +807,24 @@ difftm(struct tm *a, struct tm *b)
time_t
cvs_date_parse(const char *p)
{
- struct tm gmt, *gmt_ptr, *tm;
- struct timeb ftz, *now;
- time_t Start, tod, nowtime;
+ struct tm gmt, tm;
+ time_t Start, tod, nowtime, tz;
yyInput = p;
- now = &ftz;
- (void)time(&nowtime);
+ if (time(&nowtime) == -1 || !gmtime_r(&nowtime, &gmt) ||
+ !localtime_r(&nowtime, &tm))
+ fatal("cvs_date_parse failed");
- gmt_ptr = gmtime(&nowtime);
- if (gmt_ptr != NULL) {
- /* Make a copy, in case localtime modifies *tm (I think
- * that comment now applies to *gmt_ptr, but I am too
- * lazy to dig into how gmtime and locatime allocate the
- * structures they return pointers to).
- */
- gmt = *gmt_ptr;
- }
-
- if (!(tm = localtime(&nowtime)))
- return (-1);
-
- if (gmt_ptr != NULL)
- ftz.timezone = difftm(&gmt, tm) / 60;
+ tz = difftm(&gmt, &tm) / 60;
- if (tm->tm_isdst)
- ftz.timezone += 60;
+ if (tm.tm_isdst)
+ tz += 60;
- tm = localtime(&nowtime);
- yyYear = tm->tm_year + 1900;
- yyMonth = tm->tm_mon + 1;
- yyDay = tm->tm_mday;
- yyTimezone = now->timezone;
+ yyYear = tm.tm_year + 1900;
+ yyMonth = tm.tm_mon + 1;
+ yyDay = tm.tm_mday;
+ yyTimezone = tz;
yyDSTmode = DSTmaybe;
yyHour = 0;
yyMinutes = 0;
@@ -865,8 +850,8 @@ cvs_date_parse(const char *p)
} else {
Start = nowtime;
if (!yyHaveRel)
- Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) +
- tm->tm_sec;
+ Start -= ((tm.tm_hour * 60L + tm.tm_min) * 60L) +
+ tm.tm_sec;
}
Start += yyRelSeconds;