const char *fmt;
time_t mtime;
static time_t now;
+ struct tm *ltime;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tmbuf;
+#endif
if (!now)
time(&now);
else
fmt = cpio->day_first ? "%e %b %H:%M" : "%b %e %H:%M";
#endif
- strftime(date, sizeof(date), fmt, localtime(&mtime));
+#ifdef HAVE_LOCALTIME_R
+ ltime = localtime_r(&mtime, &tmbuf);
+#else
+ ltime = localtime(&mtime)
+#endif
+ strftime(date, sizeof(date), fmt, ltime);
fprintf(out, "%s%3d %-8s %-8s %8s %12s %s",
archive_entry_strmode(entry),
** This code is in the public domain and has no copyright.
*/
+#include "archive_platform.h"
#ifdef __FreeBSD__
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
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;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tmbuf;
+#endif
if (Year < 69)
Year += 2000;
Julian *= DAY;
Julian += Timezone;
Julian += Hours * HOUR + Minutes * MINUTE + Seconds;
+#ifdef HAVE_LOCALTIME_R
+ ltime = localtime_r(&Julian, &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;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tmbuf;
+#endif
- StartDay = (localtime(&Start)->tm_hour + 1) % 24;
- FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
+#ifdef HAVE_LOCALTIME_R
+ ltime = localtime_r(&Start, &tmbuf);
+#else
+ ltime = localtime(&Start);
+#endif
+ StartDay = (ltime->tm_hour + 1) % 24;
+#ifdef HAVE_LOCALTIME_R
+ ltime = localtime_r(&Future, &tmbuf);
+#else
+ ltime = localtime(&Future);
+#endif
+ FutureDay = (ltime->tm_hour + 1) % 24;
return (Future - Start) + (StartDay - FutureDay) * HOUR;
}
{
struct tm *tm;
time_t t, now;
+#ifdef HAVE_GMTIME_R
+ struct tm tmbuf;
+#endif
t = Start - zone;
+#ifdef HAVE_GMTIME_R
+ tm = gmtime_r(&t, &tmbuf);
+#else
tm = gmtime(&t);
+#endif
now = Start;
now += DAY * ((DayNumber - tm->tm_wday + 7) % 7);
now += 7 * DAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
struct tm *tm;
time_t Month;
time_t Year;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tmbuf;
+#endif
if (RelMonth == 0)
return 0;
+#ifdef HAVE_LOCALTIME_R
+ tm = localtime_r(&Start, &tmbuf);
+#else
tm = localtime(&Start);
+#endif
Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth;
Year = Month / 12;
Month = Month % 12 + 1;
gds = &_gds;
/* Look up the current time. */
+#ifdef HAVE_LOCALTIME_R
+ tm = localtime_r(&now, &local);
+#else
memset(&local, 0, sizeof(local));
- tm = localtime (&now);
+ tm = localtime(&now);
+#endif
if (tm == NULL)
return -1;
+#ifndef HAVE_LOCALTIME_R
local = *tm;
+#endif
/* Look up UTC if we can and use that to determine the current
* timezone offset. */
+#ifdef HAVE_GMTIME_R
+ gmt_ptr = gmtime_r(&now, &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
* time components instead of the local timezone. */
if (gds->HaveZone && gmt_ptr != NULL) {
now -= gds->Timezone;
- gmt_ptr = gmtime (&now);
+#ifdef HAVE_GMTIME_R
+ gmt_ptr = gmtime_r(&now, &gmt);
+#else
+ gmt_ptr = gmtime(&now);
+#endif
if (gmt_ptr != NULL)
local = *gmt_ptr;
now += gds->Timezone;
const char *fmt;
time_t tim;
static time_t now;
+ struct tm *ltime;
+#ifdef HAVE_LOCALTIME_R
+ struct tm tmbuf;
+#endif
/*
* We avoid collecting the entire list in memory at once by
fmt = bsdtar->day_first ? DAY_FMT " %b %Y" : "%b " DAY_FMT " %Y";
else
fmt = bsdtar->day_first ? DAY_FMT " %b %H:%M" : "%b " DAY_FMT " %H:%M";
- strftime(tmp, sizeof(tmp), fmt, localtime(&tim));
+#ifdef HAVE_LOCALTIME_R
+ ltime = localtime_r(&tim, &tmbuf);
+#else
+ ltime = localtime(&tim);
+#endif
+ strftime(tmp, sizeof(tmp), fmt, ltime);
fprintf(out, " %s ", tmp);
safe_fprintf(out, "%s", archive_entry_pathname(entry));