Annotation of linux/kernel/mktime.c, revision 1.1

1.1     ! root        1: #include <time.h>
        !             2: 
        !             3: /*
        !             4:  * This isn't the library routine, it is only used in the kernel.
        !             5:  * as such, we don't care about years<1970 etc, but assume everything
        !             6:  * is ok. Similarly, TZ etc is happily ignored. We just do everything
        !             7:  * as easily as possible. Let's find something public for the library
        !             8:  * routines (although I think minix times is public).
        !             9:  */
        !            10: /*
        !            11:  * PS. I hate whoever though up the year 1970 - couldn't they have gotten
        !            12:  * a leap-year instead? I also hate Gregorius, pope or no. I'm grumpy.
        !            13:  */
        !            14: #define MINUTE 60
        !            15: #define HOUR (60*MINUTE)
        !            16: #define DAY (24*HOUR)
        !            17: #define YEAR (365*DAY)
        !            18: 
        !            19: /* interestingly, we assume leap-years */
        !            20: static int month[12] = {
        !            21:        0,
        !            22:        DAY*(31),
        !            23:        DAY*(31+29),
        !            24:        DAY*(31+29+31),
        !            25:        DAY*(31+29+31+30),
        !            26:        DAY*(31+29+31+30+31),
        !            27:        DAY*(31+29+31+30+31+30),
        !            28:        DAY*(31+29+31+30+31+30+31),
        !            29:        DAY*(31+29+31+30+31+30+31+31),
        !            30:        DAY*(31+29+31+30+31+30+31+31+30),
        !            31:        DAY*(31+29+31+30+31+30+31+31+30+31),
        !            32:        DAY*(31+29+31+30+31+30+31+31+30+31+30)
        !            33: };
        !            34: 
        !            35: long kernel_mktime(struct tm * tm)
        !            36: {
        !            37:        long res;
        !            38:        int year;
        !            39: 
        !            40:        year = tm->tm_year - 70;
        !            41: /* magic offsets (y+1) needed to get leapyears right.*/
        !            42:        res = YEAR*year + DAY*((year+1)/4);
        !            43:        res += month[tm->tm_mon];
        !            44: /* and (y+2) here. If it wasn't a leap-year, we have to adjust */
        !            45:        if (tm->tm_mon>1 && ((year+2)%4))
        !            46:                res -= DAY;
        !            47:        res += DAY*(tm->tm_mday-1);
        !            48:        res += HOUR*tm->tm_hour;
        !            49:        res += MINUTE*tm->tm_min;
        !            50:        res += tm->tm_sec;
        !            51:        return res;
        !            52: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.