diff --git a/archival/libunarchive/header_verbose_list.c b/archival/libunarchive/header_verbose_list.c index da21a15af..f6f04cfd5 100644 --- a/archival/libunarchive/header_verbose_list.c +++ b/archival/libunarchive/header_verbose_list.c @@ -8,7 +8,8 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header) { - struct tm *mtime = localtime(&(file_header->mtime)); + struct tm tm_time; + struct tm *ptm = &tm_time; //localtime(&file_header->mtime); #if ENABLE_FEATURE_TAR_UNAME_GNAME char uid[sizeof(int)*3 + 2]; @@ -16,6 +17,8 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header) char *user; char *group; + localtime_r(&file_header->mtime, ptm); + user = file_header->tar__uname; if (user == NULL) { sprintf(uid, "%u", (unsigned)file_header->uid); @@ -31,26 +34,31 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header) user, group, file_header->size, - 1900 + mtime->tm_year, - 1 + mtime->tm_mon, - mtime->tm_mday, - mtime->tm_hour, - mtime->tm_min, - mtime->tm_sec, + 1900 + ptm->tm_year, + 1 + ptm->tm_mon, + ptm->tm_mday, + ptm->tm_hour, + ptm->tm_min, + ptm->tm_sec, file_header->name); + #else /* !FEATURE_TAR_UNAME_GNAME */ + + localtime_r(&file_header->mtime, ptm); + printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s", bb_mode_string(file_header->mode), (unsigned)file_header->uid, (unsigned)file_header->gid, file_header->size, - 1900 + mtime->tm_year, - 1 + mtime->tm_mon, - mtime->tm_mday, - mtime->tm_hour, - mtime->tm_min, - mtime->tm_sec, + 1900 + ptm->tm_year, + 1 + ptm->tm_mon, + ptm->tm_mday, + ptm->tm_hour, + ptm->tm_min, + ptm->tm_sec, file_header->name); + #endif /* FEATURE_TAR_UNAME_GNAME */ if (file_header->link_target) { diff --git a/archival/rpm.c b/archival/rpm.c index cdaf50fa9..6c1e341cd 100644 --- a/archival/rpm.c +++ b/archival/rpm.c @@ -145,13 +145,13 @@ int rpm_main(int argc, char **argv) if (func & rpm_query_info) { /* Do the nice printout */ time_t bdate_time; - struct tm *bdate; + struct tm *bdate_ptm; char bdatestring[50]; printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_PREFIXS, 0) ? rpm_getstr(TAG_PREFIXS, 0) : "(not relocateable)"); printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_VENDOR, 0) ? rpm_getstr(TAG_VENDOR, 0) : "(none)"); bdate_time = rpm_getint(TAG_BUILDTIME, 0); - bdate = localtime((time_t *) &bdate_time); - strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate); + bdate_ptm = localtime(&bdate_time); + strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm); printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring); printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0)); printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), rpm_getstr(TAG_SOURCERPM, 0)); diff --git a/coreutils/cal.c b/coreutils/cal.c index 823644226..e6f9af937 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c @@ -79,7 +79,6 @@ static char *build_row(char *p, unsigned *dp); int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int cal_main(int argc UNUSED_PARAM, char **argv) { - struct tm *local_time; struct tm zero_tm; time_t now; unsigned month, year, flags, i; @@ -94,11 +93,13 @@ int cal_main(int argc UNUSED_PARAM, char **argv) argv += optind; if (!argv[0]) { + struct tm *ptm; + time(&now); - local_time = localtime(&now); - year = local_time->tm_year + 1900; + ptm = localtime(&now); + year = ptm->tm_year + 1900; if (!(flags & 2)) { /* no -y */ - month = local_time->tm_mon + 1; + month = ptm->tm_mon + 1; } } else { if (argv[1]) { diff --git a/include/libbb.h b/include/libbb.h index cda59dc1f..e07bb52f6 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -444,8 +444,8 @@ struct BUG_too_small { }; -void parse_datestr(const char *date_str, struct tm *tm_time) FAST_FUNC; -time_t validate_tm_time(const char *date_str, struct tm *tm_time) FAST_FUNC; +void parse_datestr(const char *date_str, struct tm *ptm) FAST_FUNC; +time_t validate_tm_time(const char *date_str, struct tm *ptm) FAST_FUNC; int xsocket(int domain, int type, int protocol) FAST_FUNC; diff --git a/include/rtc_.h b/include/rtc_.h index 2b4ae778d..b5fe8ec32 100644 --- a/include/rtc_.h +++ b/include/rtc_.h @@ -13,8 +13,8 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN int rtc_adjtime_is_utc(void) FAST_FUNC; int rtc_xopen(const char **default_rtc, int flags) FAST_FUNC; -void rtc_read_tm(struct tm *tm, int fd) FAST_FUNC; -time_t rtc_tm2time(struct tm *tm, int utc) FAST_FUNC; +void rtc_read_tm(struct tm *ptm, int fd) FAST_FUNC; +time_t rtc_tm2time(struct tm *ptm, int utc) FAST_FUNC; /* diff --git a/libbb/rtc.c b/libbb/rtc.c index 9807e1cf9..fcd6c64d7 100644 --- a/libbb/rtc.c +++ b/libbb/rtc.c @@ -59,14 +59,14 @@ int FAST_FUNC rtc_xopen(const char **default_rtc, int flags) return xopen(*default_rtc, flags); } -void FAST_FUNC rtc_read_tm(struct tm *tm, int fd) +void FAST_FUNC rtc_read_tm(struct tm *ptm, int fd) { - memset(tm, 0, sizeof(*tm)); - xioctl(fd, RTC_RD_TIME, tm); - tm->tm_isdst = -1; /* "not known" */ + memset(ptm, 0, sizeof(*ptm)); + xioctl(fd, RTC_RD_TIME, ptm); + ptm->tm_isdst = -1; /* "not known" */ } -time_t FAST_FUNC rtc_tm2time(struct tm *tm, int utc) +time_t FAST_FUNC rtc_tm2time(struct tm *ptm, int utc) { char *oldtz = oldtz; /* for compiler */ time_t t; @@ -77,7 +77,7 @@ time_t FAST_FUNC rtc_tm2time(struct tm *tm, int utc) tzset(); } - t = mktime(tm); + t = mktime(ptm); if (utc) { unsetenv("TZ"); diff --git a/libbb/time.c b/libbb/time.c index 85c72d163..82a0fa1fa 100644 --- a/libbb/time.c +++ b/libbb/time.c @@ -8,51 +8,51 @@ */ #include "libbb.h" -void FAST_FUNC parse_datestr(const char *date_str, struct tm *tm_time) +void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm) { char end = '\0'; const char *last_colon = strrchr(date_str, ':'); if (last_colon != NULL) { - /* Parse input and assign appropriately to tm_time */ + /* Parse input and assign appropriately to ptm */ /* HH:MM */ if (sscanf(date_str, "%u:%u%c", - &tm_time->tm_hour, - &tm_time->tm_min, + &ptm->tm_hour, + &ptm->tm_min, &end) >= 2) { /* no adjustments needed */ } else /* mm.dd-HH:MM */ if (sscanf(date_str, "%u.%u-%u:%u%c", - &tm_time->tm_mon, &tm_time->tm_mday, - &tm_time->tm_hour, &tm_time->tm_min, + &ptm->tm_mon, &ptm->tm_mday, + &ptm->tm_hour, &ptm->tm_min, &end) >= 4) { /* Adjust month from 1-12 to 0-11 */ - tm_time->tm_mon -= 1; + ptm->tm_mon -= 1; } else /* yyyy.mm.dd-HH:MM */ - if (sscanf(date_str, "%u.%u.%u-%u:%u%c", &tm_time->tm_year, - &tm_time->tm_mon, &tm_time->tm_mday, - &tm_time->tm_hour, &tm_time->tm_min, + if (sscanf(date_str, "%u.%u.%u-%u:%u%c", &ptm->tm_year, + &ptm->tm_mon, &ptm->tm_mday, + &ptm->tm_hour, &ptm->tm_min, &end) >= 5) { - tm_time->tm_year -= 1900; /* Adjust years */ - tm_time->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ + ptm->tm_year -= 1900; /* Adjust years */ + ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ } else /* yyyy-mm-dd HH:MM */ - if (sscanf(date_str, "%u-%u-%u %u:%u%c", &tm_time->tm_year, - &tm_time->tm_mon, &tm_time->tm_mday, - &tm_time->tm_hour, &tm_time->tm_min, + if (sscanf(date_str, "%u-%u-%u %u:%u%c", &ptm->tm_year, + &ptm->tm_mon, &ptm->tm_mday, + &ptm->tm_hour, &ptm->tm_min, &end) >= 5) { - tm_time->tm_year -= 1900; /* Adjust years */ - tm_time->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ + ptm->tm_year -= 1900; /* Adjust years */ + ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ //TODO: coreutils 6.9 also accepts "yyyy-mm-dd HH" (no minutes) } else { bb_error_msg_and_die(bb_msg_invalid_date, date_str); } if (end == ':') { /* xxx:SS */ - if (sscanf(last_colon + 1, "%u%c", &tm_time->tm_sec, &end) == 1) + if (sscanf(last_colon + 1, "%u%c", &ptm->tm_sec, &end) == 1) end = '\0'; /* else end != NUL and we error out */ } @@ -75,60 +75,60 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *tm_time) /* MM[.SS] */ if (len == 2 && sscanf(date_str, "%2u%2u%2u%2u""%2u%c" + 12, - &tm_time->tm_min, + &ptm->tm_min, &end) >= 1) { } else /* HHMM[.SS] */ if (len == 4 && sscanf(date_str, "%2u%2u%2u""%2u%2u%c" + 9, - &tm_time->tm_hour, - &tm_time->tm_min, + &ptm->tm_hour, + &ptm->tm_min, &end) >= 2) { } else /* ddHHMM[.SS] */ if (len == 6 && sscanf(date_str, "%2u%2u""%2u%2u%2u%c" + 6, - &tm_time->tm_mday, - &tm_time->tm_hour, - &tm_time->tm_min, + &ptm->tm_mday, + &ptm->tm_hour, + &ptm->tm_min, &end) >= 3) { } else /* mmddHHMM[.SS] */ if (len == 8 && sscanf(date_str, "%2u""%2u%2u%2u%2u%c" + 3, - &tm_time->tm_mon, - &tm_time->tm_mday, - &tm_time->tm_hour, - &tm_time->tm_min, + &ptm->tm_mon, + &ptm->tm_mday, + &ptm->tm_hour, + &ptm->tm_min, &end) >= 4) { /* Adjust month from 1-12 to 0-11 */ - tm_time->tm_mon -= 1; + ptm->tm_mon -= 1; } else /* yymmddHHMM[.SS] */ if (len == 10 && sscanf(date_str, "%2u%2u%2u%2u%2u%c", - &tm_time->tm_year, - &tm_time->tm_mon, - &tm_time->tm_mday, - &tm_time->tm_hour, - &tm_time->tm_min, + &ptm->tm_year, + &ptm->tm_mon, + &ptm->tm_mday, + &ptm->tm_hour, + &ptm->tm_min, &end) >= 5) { /* Adjust month from 1-12 to 0-11 */ - tm_time->tm_mon -= 1; + ptm->tm_mon -= 1; } else /* ccyymmddHHMM[.SS] */ if (len == 12 && sscanf(date_str, "%4u%2u%2u%2u%2u%c", - &tm_time->tm_year, - &tm_time->tm_mon, - &tm_time->tm_mday, - &tm_time->tm_hour, - &tm_time->tm_min, + &ptm->tm_year, + &ptm->tm_mon, + &ptm->tm_mday, + &ptm->tm_hour, + &ptm->tm_min, &end) >= 5) { - tm_time->tm_year -= 1900; /* Adjust years */ - tm_time->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ + ptm->tm_year -= 1900; /* Adjust years */ + ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ } else { bb_error_msg_and_die(bb_msg_invalid_date, date_str); } if (end == '.') { /* xxx.SS */ if (sscanf(strchr(date_str, '.') + 1, "%u%c", - &tm_time->tm_sec, &end) == 1) + &ptm->tm_sec, &end) == 1) end = '\0'; /* else end != NUL and we error out */ } @@ -138,9 +138,9 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *tm_time) } } -time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *tm_time) +time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *ptm) { - time_t t = mktime(tm_time); + time_t t = mktime(ptm); if (t == (time_t) -1L) { bb_error_msg_and_die(bb_msg_invalid_date, date_str); } diff --git a/miscutils/crond.c b/miscutils/crond.c index ad217f007..7135e4475 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -654,14 +654,14 @@ static int TestJobs(time_t t1, time_t t2) /* Find jobs > t1 and <= t2 */ for (t = t1 - t1 % 60; t <= t2; t += 60) { - struct tm *tp; + struct tm *ptm; CronFile *file; CronLine *line; if (t <= t1) continue; - tp = localtime(&t); + ptm = localtime(&t); for (file = FileBase; file; file = file->cf_Next) { if (DebugOpt) crondlog(LVL5 "file %s:", file->cf_User); @@ -670,9 +670,9 @@ static int TestJobs(time_t t1, time_t t2) for (line = file->cf_LineBase; line; line = line->cl_Next) { if (DebugOpt) crondlog(LVL5 " line %s", line->cl_Shell); - if (line->cl_Mins[tp->tm_min] && line->cl_Hrs[tp->tm_hour] - && (line->cl_Days[tp->tm_mday] || line->cl_Dow[tp->tm_wday]) - && line->cl_Mons[tp->tm_mon] + if (line->cl_Mins[ptm->tm_min] && line->cl_Hrs[ptm->tm_hour] + && (line->cl_Days[ptm->tm_mday] || line->cl_Dow[ptm->tm_wday]) + && line->cl_Mons[ptm->tm_mon] ) { if (DebugOpt) { crondlog(LVL5 " job: %d %s", diff --git a/networking/httpd_indexcgi.c b/networking/httpd_indexcgi.c index 6663a22ad..9fa7c7481 100644 --- a/networking/httpd_indexcgi.c +++ b/networking/httpd_indexcgi.c @@ -291,7 +291,7 @@ int main(int argc, char *argv[]) size_total = 0; cdir = dir_list; while (dir_list_count--) { - struct tm *tm; + struct tm *ptm; if (S_ISDIR(cdir->dl_mode)) { count_dirs++; @@ -316,12 +316,12 @@ int main(int argc, char *argv[]) fmt_ull(cdir->dl_size); fmt_str("