2 * convdate(), convtime(), convstamp()
6 * convert MSDOS directory datestamp to ASCII.
10 convdate(date_high
, date_low
)
11 unsigned date_high
, date_low
;
15 * |7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
16 * | | | | | | | | | | | | | | | | |
17 * \ 7 bits /\4 bits/\ 5 bits /
21 unsigned char year
, month_hi
, month_low
, day
;
23 year
= (date_high
>> 1) + 80;
24 month_hi
= (date_high
& 0x1) << 3;
25 month_low
= date_low
>> 5;
26 day
= date_low
& 0x1f;
27 sprintf(ans
, "%2d-%02d-%02d", month_hi
+month_low
, day
, year
);
32 * Convert MSDOS directory timestamp to ASCII.
36 convtime(time_high
, time_low
)
37 unsigned time_high
, time_low
;
41 * |7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
42 * | | | | | | | | | | | | | | | | |
43 * \ 5 bits /\ 6 bits /\ 5 bits /
48 unsigned char hour
, min_hi
, min_low
;
50 hour
= time_high
>> 3;
51 am_pm
= (hour
>= 12) ? 'p' : 'a';
56 min_hi
= (time_high
& 0x7) << 3;
57 min_low
= time_low
>> 5;
58 sprintf(ans
, "%2d:%02d%c", hour
, min_hi
+min_low
, am_pm
);
63 * Convert a MSDOS time & date stamp to the Unix time() format
67 convstamp(time_field
, date_field
)
68 unsigned char *time_field
, *date_field
;
71 int year
, mon
, mday
, hour
, min
, sec
, old_leaps
;
72 long answer
, sec_year
, sec_mon
, sec_mday
, sec_hour
, sec_min
, sec_leap
;
73 static int month
[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304,
75 /* disect the parts */
76 year
= (date_field
[1] >> 1) + 1980;
77 mon
= (((date_field
[1] & 0x1) << 3) + (date_field
[0] >> 5));
78 mday
= date_field
[0] & 0x1f;
79 hour
= time_field
[1] >> 3;
80 min
= (((time_field
[1] & 0x7) << 3) + (time_field
[0] >> 5));
81 sec
= (time_field
[0] & 0x1f) * 2;
82 /* how many previous leap years */
83 old_leaps
= (year
-1972) / 4;
84 sec_leap
= old_leaps
* 24 * 60 * 60;
85 /* back off 1 day if before 29 Feb */
86 if (!(year
% 4) && mon
< 3)
87 sec_leap
-= 24 * 60 * 60;
88 sec_year
= (year
- 1970) * 365 * 24 * 60 * 60;
89 sec_mon
= month
[mon
-1] * 24 * 60 * 60;
90 sec_mday
= mday
* 24 * 60 * 60;
91 sec_hour
= hour
* 60 * 60;
94 answer
= sec_leap
+ sec_year
+ sec_mon
+ sec_mday
+ sec_hour
+ sec_min
+ sec
/* + timezone*/;