aboutsummaryrefslogtreecommitdiff
path: root/contrib/libarchive/libarchive/archive_getdate.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libarchive/libarchive/archive_getdate.c')
-rw-r--r--contrib/libarchive/libarchive/archive_getdate.c149
1 files changed, 138 insertions, 11 deletions
diff --git a/contrib/libarchive/libarchive/archive_getdate.c b/contrib/libarchive/libarchive/archive_getdate.c
index 030c083ce716..3ec5bba88896 100644
--- a/contrib/libarchive/libarchive/archive_getdate.c
+++ b/contrib/libarchive/libarchive/archive_getdate.c
@@ -27,6 +27,7 @@
** This code is in the public domain and has no copyright.
*/
+#include "archive_platform.h"
#ifdef __FreeBSD__
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -694,8 +695,16 @@ Convert(time_t Month, time_t Day, time_t Year,
signed char DaysInMonth[12] = {
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
- time_t Julian;
- int i;
+ time_t Julian;
+ int i;
+ struct tm *ltime;
+#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S)
+ struct tm tmbuf;
+#endif
+#if defined(HAVE__LOCALTIME64_S)
+ errno_t terr;
+ __time64_t tmptime;
+#endif
if (Year < 69)
Year += 2000;
@@ -722,21 +731,64 @@ Convert(time_t Month, time_t Day, time_t Year,
Julian *= DAY;
Julian += Timezone;
Julian += Hours * HOUR + Minutes * MINUTE + Seconds;
+#if defined(HAVE_LOCALTIME_R)
+ ltime = localtime_r(&Julian, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = Julian;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ ltime = NULL;
+ else
+ ltime = &tmbuf;
+#else
+ ltime = localtime(&Julian);
+#endif
if (DSTmode == DSTon
- || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
+ || (DSTmode == DSTmaybe && ltime->tm_isdst))
Julian -= HOUR;
return Julian;
}
-
static time_t
DSTcorrect(time_t Start, time_t Future)
{
- time_t StartDay;
- time_t FutureDay;
+ time_t StartDay;
+ time_t FutureDay;
+ struct tm *ltime;
+#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S)
+ struct tm tmbuf;
+#endif
+#if defined(HAVE__LOCALTIME64_S)
+ errno_t terr;
+ __time64_t tmptime;
+#endif
- StartDay = (localtime(&Start)->tm_hour + 1) % 24;
- FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
+#if defined(HAVE_LOCALTIME_R)
+ ltime = localtime_r(&Start, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = Start;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ ltime = NULL;
+ else
+ ltime = &tmbuf;
+#else
+ ltime = localtime(&Start);
+#endif
+ StartDay = (ltime->tm_hour + 1) % 24;
+#if defined(HAVE_LOCALTIME_R)
+ ltime = localtime_r(&Future, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = Future;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ ltime = NULL;
+ else
+ ltime = &tmbuf;
+#else
+ ltime = localtime(&Future);
+#endif
+ FutureDay = (ltime->tm_hour + 1) % 24;
return (Future - Start) + (StartDay - FutureDay) * HOUR;
}
@@ -747,9 +799,27 @@ RelativeDate(time_t Start, time_t zone, int dstmode,
{
struct tm *tm;
time_t t, now;
+#if defined(HAVE_GMTIME_R) || defined(HAVE__GMTIME64_S)
+ struct tm tmbuf;
+#endif
+#if defined(HAVE__GMTIME64_S)
+ errno_t terr;
+ __time64_t tmptime;
+#endif
t = Start - zone;
+#if defined(HAVE_GMTIME_R)
+ tm = gmtime_r(&t, &tmbuf);
+#elif defined(HAVE__GMTIME64_S)
+ tmptime = t;
+ terr = _gmtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ tm = NULL;
+ else
+ tm = &tmbuf;
+#else
tm = gmtime(&t);
+#endif
now = Start;
now += DAY * ((DayNumber - tm->tm_wday + 7) % 7);
now += 7 * DAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
@@ -765,10 +835,28 @@ RelativeMonth(time_t Start, time_t Timezone, time_t RelMonth)
struct tm *tm;
time_t Month;
time_t Year;
+#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S)
+ struct tm tmbuf;
+#endif
+#if defined(HAVE__LOCALTIME64_S)
+ errno_t terr;
+ __time64_t tmptime;
+#endif
if (RelMonth == 0)
return 0;
+#if defined(HAVE_LOCALTIME_R)
+ tm = localtime_r(&Start, &tmbuf);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = Start;
+ terr = _localtime64_s(&tmbuf, &tmptime);
+ if (terr)
+ tm = NULL;
+ else
+ tm = &tmbuf;
+#else
tm = localtime(&Start);
+#endif
Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth;
Year = Month / 12;
Month = Month % 12 + 1;
@@ -905,6 +993,10 @@ __archive_get_date(time_t now, const char *p)
time_t Start;
time_t tod;
long tzone;
+#if defined(HAVE__LOCALTIME64_S) || defined(HAVE__GMTIME64_S)
+ errno_t terr;
+ __time64_t tmptime;
+#endif
/* Clear out the parsed token array. */
memset(tokens, 0, sizeof(tokens));
@@ -913,20 +1005,44 @@ __archive_get_date(time_t now, const char *p)
gds = &_gds;
/* Look up the current time. */
+#if defined(HAVE_LOCALTIME_R)
+ tm = localtime_r(&now, &local);
+#elif defined(HAVE__LOCALTIME64_S)
+ tmptime = now;
+ terr = _localtime64_s(&local, &tmptime);
+ if (terr)
+ tm = NULL;
+ else
+ tm = &local;
+#else
memset(&local, 0, sizeof(local));
- tm = localtime (&now);
+ tm = localtime(&now);
+#endif
if (tm == NULL)
return -1;
+#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE__LOCALTIME64_S)
local = *tm;
+#endif
/* Look up UTC if we can and use that to determine the current
* timezone offset. */
+#if defined(HAVE_GMTIME_R)
+ gmt_ptr = gmtime_r(&now, &gmt);
+#elif defined(HAVE__GMTIME64_S)
+ tmptime = now;
+ terr = _gmtime64_s(&gmt, &tmptime);
+ if (terr)
+ gmt_ptr = NULL;
+ else
+ gmt_ptr = &gmt;
+#else
memset(&gmt, 0, sizeof(gmt));
- gmt_ptr = gmtime (&now);
+ gmt_ptr = gmtime(&now);
if (gmt_ptr != NULL) {
/* Copy, in case localtime and gmtime use the same buffer. */
gmt = *gmt_ptr;
}
+#endif
if (gmt_ptr != NULL)
tzone = difftm (&gmt, &local);
else
@@ -960,7 +1076,18 @@ __archive_get_date(time_t now, const char *p)
* time components instead of the local timezone. */
if (gds->HaveZone && gmt_ptr != NULL) {
now -= gds->Timezone;
- gmt_ptr = gmtime (&now);
+#if defined(HAVE_GMTIME_R)
+ gmt_ptr = gmtime_r(&now, &gmt);
+#elif defined(HAVE__GMTIME64_S)
+ tmptime = now;
+ terr = _gmtime64_s(&gmt, &tmptime);
+ if (terr)
+ gmt_ptr = NULL;
+ else
+ gmt_ptr = &gmt;
+#else
+ gmt_ptr = gmtime(&now);
+#endif
if (gmt_ptr != NULL)
local = *gmt_ptr;
now += gds->Timezone;