1
/* dostime.c - convert dos time to/from time_t.
3
Copyright (C) 2002 Free Software Foundation
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
* The specification to which this was written. From Joe Buck.
27
* The DOS format appears to have only 2 second resolution. It is an
28
* unsigned long, and ORs together
31
* month<<21 (month is tm_mon + 1, 1=Jan through 12=Dec)
32
* day<<16 (day is tm_mday, 1-31)
33
* hour<<11 (hour is tm_hour, 0-23)
34
* min<<5 (min is tm_min, 0-59)
35
* sec>>1 (sec is tm_sec, 0-59, that's right, we throw away the LSB)
37
* DOS uses local time, so the localtime() call is used to turn the time_t
42
dos2unixtime (unsigned long dostime)
45
time_t now = time (NULL);
47
/* Call localtime to initialize timezone in TIME. */
48
ltime = *localtime (&now);
50
ltime.tm_year = (int)(dostime >> 25) + 80;
51
ltime.tm_mon = ((int)(dostime >> 21) & 0x0f) - 1;
52
ltime.tm_mday = (int)(dostime >> 16) & 0x1f;
53
ltime.tm_hour = (int)(dostime >> 11) & 0x0f;
54
ltime.tm_min = (int)(dostime >> 5) & 0x3f;
55
ltime.tm_sec = (int)(dostime & 0x1f) << 1;
61
return mktime (<ime);