⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mktime.c

📁 linux1.1源代码
💻 C
字号:
/* *  linux/kernel/mktime.c * *  Copyright (C) 1991, 1992  Linus Torvalds */#include <linux/mktime.h>/* * This isn't the library routine, it is only used in the kernel. * as such, we don't care about years<1970 etc, but assume everything * is ok. Similarly, TZ etc is happily ignored. We just do everything * as easily as possible. Let's find something public for the library * routines (although I think minix times is public). *//* * PS. I hate whoever though up the year 1970 - couldn't they have gotten * a leap-year instead? I also hate Gregorius, pope or no. I'm grumpy. */#define MINUTE 60#define HOUR (60*MINUTE)#define DAY (24*HOUR)#define YEAR (365*DAY)/* interestingly, we assume leap-years */static int month[12] = {	0,	DAY*(31),	DAY*(31+29),	DAY*(31+29+31),	DAY*(31+29+31+30),	DAY*(31+29+31+30+31),	DAY*(31+29+31+30+31+30),	DAY*(31+29+31+30+31+30+31),	DAY*(31+29+31+30+31+30+31+31),	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+30)};long kernel_mktime(struct mktime * time){	long res;	int year;	year = time->year - 70;/* magic offsets (y+1) needed to get leapyears right.*/	res = YEAR*year + DAY*((year+1)/4);	res += month[time->mon];/* and (y+2) here. If it wasn't a leap-year, we have to adjust */	if (time->mon>1 && ((year+2)%4))		res -= DAY;	res += DAY*(time->day-1);	res += HOUR*time->hour;	res += MINUTE*time->min;	res += time->sec;	return res;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -