/* * Print an MSDOS directory date stamp. */ static __inline__ void print_date(struct directory *dir) { char year[5]; char day[3]; char month[3]; const char *p; sprintf(year, "%04d", DOS_YEAR(dir)); sprintf(day, "%02d", DOS_DAY(dir)); sprintf(month, "%02d", DOS_MONTH(dir)); for(p=mtools_date_string; *p; p++) { if(!strncasecmp(p, "yyyy", 4)) { printf("%04d", DOS_YEAR(dir)); p+= 3; continue; } else if(!strncasecmp(p, "yy", 2)) { printf("%02d", DOS_YEAR(dir) % 100); p++; continue; } else if(!strncasecmp(p, "dd", 2)) { printf("%02d", DOS_DAY(dir)); p++; continue; } else if(!strncasecmp(p, "mm", 2)) { printf("%02d", DOS_MONTH(dir)); p++; continue; } putchar(*p); } }
static inline time_t conv_stamp(struct directory *dir) { struct tm *tmbuf; long tzone, dst; time_t accum, tmp; accum = DOS_YEAR(dir) - 1970; /* years past */ /* days passed */ accum = accum * 365L + month[DOS_MONTH(dir)-1] + DOS_DAY(dir); /* leap years */ accum += (DOS_YEAR(dir) - 1972) / 4L; /* back off 1 day if before 29 Feb */ if (!(DOS_YEAR(dir) % 4) && DOS_MONTH(dir) < 3) accum--; accum = accum * 24L + DOS_HOUR(dir); /* hours passed */ accum = accum * 60L + DOS_MINUTE(dir); /* minutes passed */ accum = accum * 60L + DOS_SEC(dir); /* seconds passed */ #ifndef OS_Minix /* correct for Time Zone */ #ifdef HAVE_GETTIMEOFDAY { struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); tzone = tz.tz_minuteswest * 60L; } #else #ifdef HAVE_TZSET { #ifndef OS_ultrix /* Ultrix defines this to be a different type */ extern long timezone; #endif tzset(); tzone = (long) timezone; } #else tzone = 0; #endif /* HAVE_TZSET */ #endif /* HAVE_GETTIMEOFDAY */ accum += tzone; #endif /* OS_Minix */ /* correct for Daylight Saving Time */ tmp = accum; tmbuf = localtime(&tmp); #ifndef OS_Minix dst = (tmbuf->tm_isdst) ? (-60L * 60L) : 0L; accum += dst; #endif return accum; }