OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [fs/] [isofs/] [util.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  linux/fs/isofs/util.c
3
 */
4
 
5
#include <linux/time.h>
6
#include <linux/iso_fs.h>
7
 
8
/*
9
 * We have to convert from a MM/DD/YY format to the Unix ctime format.
10
 * We have to take into account leap years and all of that good stuff.
11
 * Unfortunately, the kernel does not have the information on hand to
12
 * take into account daylight savings time, but it shouldn't matter.
13
 * The time stored should be localtime (with or without DST in effect),
14
 * and the timezone offset should hold the offset required to get back
15
 * to GMT.  Thus  we should always be correct.
16
 */
17
 
18
int iso_date(char * p, int flag)
19
{
20
        int year, month, day, hour, minute, second, tz;
21
        int crtime, days, i;
22
 
23
        year = p[0] - 70;
24
        month = p[1];
25
        day = p[2];
26
        hour = p[3];
27
        minute = p[4];
28
        second = p[5];
29
        if (flag == 0) tz = p[6]; /* High sierra has no time zone */
30
        else tz = 0;
31
 
32
        if (year < 0) {
33
                crtime = 0;
34
        } else {
35
                int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
36
 
37
                days = year * 365;
38
                if (year > 2)
39
                        days += (year+1) / 4;
40
                for (i = 1; i < month; i++)
41
                        days += monlen[i-1];
42
                if (((year+2) % 4) == 0 && month > 2)
43
                        days++;
44
                days += day - 1;
45
                crtime = ((((days * 24) + hour) * 60 + minute) * 60)
46
                        + second;
47
 
48
                /* sign extend */
49
                if (tz & 0x80)
50
                        tz |= (-1 << 8);
51
 
52
                /*
53
                 * The timezone offset is unreliable on some disks,
54
                 * so we make a sanity check.  In no case is it ever
55
                 * more than 13 hours from GMT, which is 52*15min.
56
                 * The time is always stored in localtime with the
57
                 * timezone offset being what get added to GMT to
58
                 * get to localtime.  Thus we need to subtract the offset
59
                 * to get to true GMT, which is what we store the time
60
                 * as internally.  On the local system, the user may set
61
                 * their timezone any way they wish, of course, so GMT
62
                 * gets converted back to localtime on the receiving
63
                 * system.
64
                 *
65
                 * NOTE: mkisofs in versions prior to mkisofs-1.10 had
66
                 * the sign wrong on the timezone offset.  This has now
67
                 * been corrected there too, but if you are getting screwy
68
                 * results this may be the explanation.  If enough people
69
                 * complain, a user configuration option could be added
70
                 * to add the timezone offset in with the wrong sign
71
                 * for 'compatibility' with older discs, but I cannot see how
72
                 * it will matter that much.
73
                 *
74
                 * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann)
75
                 * for pointing out the sign error.
76
                 */
77
                if (-52 <= tz && tz <= 52)
78
                        crtime -= tz * 15 * 60;
79
        }
80
        return crtime;
81
}
82
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.