~ubuntu-branches/ubuntu/oneiric/strigi/oneiric

« back to all changes in this revision

Viewing changes to src/streams/dostime.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2011-09-20 08:50:25 UTC
  • mto: (1.1.20 upstream) (5.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110920085025-wszfu6x8rshrjq0e
ImportĀ upstreamĀ versionĀ 0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* dostime.c - convert dos time to/from time_t.
2
 
 
3
 
   Copyright (C) 2002 Free Software Foundation
4
 
 
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.
9
 
 
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.
14
 
 
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.
18
 
*/
19
 
 
20
 
#include "dostime.h"
21
 
 
22
 
#include <stddef.h>
23
 
 
24
 
 
25
 
/*
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
29
 
 *
30
 
 * (year-1980)<<25
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)
36
 
 *
37
 
 * DOS uses local time, so the localtime() call is used to turn the time_t
38
 
 * into a struct tm.
39
 
 */
40
 
 
41
 
time_t
42
 
dos2unixtime (unsigned long dostime)
43
 
{
44
 
  struct tm ltime;
45
 
  time_t now = time (NULL);
46
 
 
47
 
  /* Call localtime to initialize timezone in TIME.  */
48
 
  ltime = *localtime (&now);
49
 
 
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;
56
 
 
57
 
  ltime.tm_wday = -1;
58
 
  ltime.tm_yday = -1;
59
 
  ltime.tm_isdst = -1;
60
 
 
61
 
  return mktime (&ltime);
62
 
}