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

📄 etc.c

📁 UNIX/LINUX平台下面SMS网管原代码
💻 C
📖 第 1 页 / 共 2 页
字号:
int ComputeTime(char *start, char *end){	char p_h[3], q_h[3];	char p_m[3], q_m[3];	char p_s[3], q_s[3];	int  h, m, s, tmptime = 0;	memset(p_h, 0, sizeof(p_h));	memset(q_h, 0, sizeof(p_h));	GetField(start, ':', p_h, 1);	GetField(end, ':', q_h, 1);	memset(p_m, 0, sizeof(p_m));	memset(q_m, 0, sizeof(p_m));	GetField(start, ':', p_m, 2);	GetField(end, ':', q_m, 2);	GetField(start, ':', p_s, 3);	GetField(end, ':', q_s, 3);	tmptime = (60*60*atoi(q_h) + 60*atoi(q_m) + atoi(q_s)) - \		  (60*60*atoi(p_h) + 60*atoi(p_m) + atoi(p_s));	return tmptime;}/* * function	: ComputeTimeL * params	: start - 131010 *		: end   - 141009 * return	: time in seconds */int ComputeTimeL(char *start, char *end){	char p_h[3], q_h[3];	char p_m[3], q_m[3];	char p_s[3], q_s[3];	int  h, m, s, tmptime = 0;	memset(p_h, 0, sizeof(p_h));	memset(q_h, 0, sizeof(p_h));	memcpy(p_h, start + 0, 2);	memcpy(q_h, end + 0, 2);	memset(p_m, 0, sizeof(p_m));	memset(q_m, 0, sizeof(p_m));	memcpy(p_m, start + 2, 2);	memcpy(q_m, end + 2, 2);/**	memcpy(p_s, start + 4, 2);	memcpy(q_s, end + 4, 2); **/	sprintf(p_s, "%c%c", start[4], start[5]);	sprintf(q_s, "%c%c", end[4], end[5]);	tmptime = (60*60*atoi(q_h) + 60*atoi(q_m) + atoi(q_s)) - \		  (60*60*atoi(p_h) + 60*atoi(p_m) + atoi(p_s));	return tmptime;}int IsNullStr(char *string){	char *p;	int  result = 0;        p = string;        for(; *p; p++) 	{		if(*p != ' ')		{			result = 1;			break;		}	}	return result;}/* * function	: string function */char *RightTrim(char *string ){	int n = strlen( string ) - 1;	while( n > 0 )	{		if ( *( string + n ) != ' ' )	{		*( string + n + 1 ) = 0;		break;	}		else		n --;	}	return string;}char *LeftTrim(char *string){	while( *( string ++ ) == ' ' );	return string - 1;}char *AllTrim(char *string){	return RightTrim( LeftTrim( string ) );}/* * function	: GetSystemLimit * author	: TANG * parameters	:  * 1.  resource - 	 *	RLIMIT_CORE (0 indicates to prevent from creating a core file. * 	RLIMIT_CPU * 	RLIMIT_DATA 	init_data + uninit_data + heap * 	RLIMIT_FSIZE * 	RLIMIT_MEMLOCK  (reserved for future use) * 	RLIMIT_NOFILE   max files opened by a process *	RLIMIT_NPROC    max number of a child process * 	RLIMIT_OFILE    the same as NOFILE *	RLIMIT_RSS  *	RLIMIT_STACK *	RLIMIT_VMEM     max size in bytes of the mapped * 2. soft_len - soft length, which can be set no more than hard_len.  *   	 	 When the actual exceeds it, a signal will be sent  *   		 to the corresponding process. * 3. hard_len - hard length, which CANNOT be set.  */int GetSystemLimit(int resource, long *soft_len, long *hard_len){	struct rlimit limit;	if( getrlimit(resource, &limit) < 0 )	{		return -1;	}	*soft_len = limit.rlim_cur;	*hard_len = limit.rlim_max;	return 0;}/* * SepChar: 0 -- no separate char, else -- the separate char * YearMode: 0 -- 4 digits, else -- 2 digits * Days: 0 -- current day, >0 -- day in the future, <0 -- day in the past  */void GetPowerDate(char *DateStr, char SepChar, int YearMode, int Days){	struct tm *curr_tm;	time_t curr_t;	char year[5];	time(&curr_t);	curr_t += (Days * 3600L * 24L);	curr_tm = localtime(&curr_t);		if (!YearMode) sprintf(year, "%04d", curr_tm->tm_year + 1900);	else sprintf(year, "%02d", curr_tm->tm_year % 100);	if (SepChar)		sprintf(DateStr, "%s%c%02d%c%02d",		                 year, SepChar,		                 curr_tm->tm_mon + 1, SepChar,		                 curr_tm->tm_mday);	else		sprintf(DateStr, "%s%02d%02d",		                 year,		                 curr_tm->tm_mon + 1,		                 curr_tm->tm_mday);}void GetPowerTime(char *TimeStr, char SepChar, int Secs){	struct tm *curr_tm;	time_t curr_t;	time(&curr_t);	curr_t += Secs;	curr_tm = localtime(&curr_t);		if (SepChar)		sprintf(TimeStr, "%02d%c%02d%c%02d",		                 curr_tm->tm_hour,SepChar,		                 curr_tm->tm_min,SepChar,		                 curr_tm->tm_sec);	else		sprintf(TimeStr, "%02d%02d%02d",		                 curr_tm->tm_hour,		                 curr_tm->tm_min,		                 curr_tm->tm_sec);}/*  * DChar, DTChar, TChar: 0 -- no separate char, else -- the separate char * YearMode: 0 -- 4 digits, else -- 2 digits*/void GetPowerDateTime(char *Str,char DChar,char DTChar,char TChar,int YearMode){	struct tm *curr_tm;	time_t curr_t;	char year[5];	char datestr[20],timestr[20];	time(&curr_t);	curr_tm = localtime(&curr_t);		if (!YearMode) sprintf(year,"%04d",curr_tm->tm_year + 1900);	else sprintf(year,"%02d",curr_tm->tm_year % 100);	if (DChar)		sprintf(datestr,"%s%c%02d%c%02d", 		                year,DChar,		                curr_tm->tm_mon + 1,DChar, 		                curr_tm->tm_mday);	else		sprintf(datestr,"%s%02d%02d", 		                year, 		                curr_tm->tm_mon + 1, 		                curr_tm->tm_mday);	if (TChar)		sprintf(timestr,"%02d%c%02d%c%02d", 		                curr_tm->tm_hour,TChar, 		                curr_tm->tm_min,TChar, 		                curr_tm->tm_sec);	else		sprintf(timestr,"%02d%02d%02d", 		                curr_tm->tm_hour, 		                curr_tm->tm_min, 		                curr_tm->tm_sec);	if (DTChar)		sprintf(Str, "%s%c%s", datestr, DTChar, timestr);	else		sprintf(Str, "%s%s", datestr, timestr);}/* * Cut off characters except 0~9 and x and X. */void PureNumber(char *purenum, char *mixnum){	char *p;	char tmp[64];	int  i = 0;	memset(tmp, 0, sizeof(tmp));	p = mixnum;	while(*p)	{		if( (*p >= 0x30 && *p <= 0x39) || *p == 0x58 || *p == 0x78 )                {                        tmp[i++] = *p;                }		p++;	}	strcpy(purenum, tmp);}/* 根据身份证生成校验位 */char GetIdMac(char *id){	int i,s,y;	char MACBIT[11]={"10X98765432"};	int W[18]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1};	s=0;	for (i=0;i<=16;i++)	{		s=s+(id[i]-48)*W[i];	}		y=s%11;		return (MACBIT[y]);}/*  * 检验18位身份证的有效性  * 可惜不能校验15位的身份证 */int CheckID(char *id){	int iLen,iRet;	char sDate[10];	char sid[18];		iLen=strlen(id);		if (iLen!=15 && iLen!=18) return -1;		memset(sDate,0,sizeof(sDate));		if (iLen==15)	{		strncpy(sDate,id+6,6);		sDate[6]=0x00;		iRet=CheckDate(sDate);		return iRet;	}	if (iLen==18)	{		strncpy(sDate,id+6,8);		sDate[8]=0x00;		iRet=CheckDate(sDate);				if (iRet<0)		{			return iRet;		}				if (id[17]!=GetIdMac(id)) return -1;		}	return 0;}/* 检验日期的有效性 */int CheckDate(char * pDate){	int iLen,iYear,iMonth,iDay;	char sYear[10],sMonth[10],sDay[10];		iLen=strlen(pDate);		if (iLen==6)	{		strncpy(sYear,pDate,2);		sYear[2]=0x00;		strncpy(sMonth,pDate+2,2);		sMonth[2]=0x00;		strncpy(sDay,pDate+4,2);		sDay[2]=0x00;	}	else if (iLen==8)	{		strncpy(sYear,pDate,4);		sYear[4]=0x00;		strncpy(sMonth,pDate+4,2);		sMonth[2]=0x00;		strncpy(sDay,pDate+6,2);		sDay[2]=0x00;	}	else if (iLen==10)	{		strncpy(sYear,pDate,4);		sYear[4]=0x00;		strncpy(sMonth,pDate+5,2);		sMonth[2]=0x00;		strncpy(sDay,pDate+8,2);		sDay[2]=0x00;	}	else		return -1;	iYear=atol(sYear);	iMonth=atoi(sMonth);	iDay=atoi(sDay);		if (strlen(sYear)==4)	{		if (iYear>2100 || iYear<1800 )	return -1;	}	if (iMonth>12 || iMonth<1) return -1;	if (iDay>31 || iDay<1)	return -1;	if (iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11)	{		if (iDay>30) return -1;	}	if (iMonth==2)	{		if ((iYear%4==0 && iYear%100!=0) || iYear%400==0 )		{			if (iDay>29)	return -1;		}		else		{			if (iDay>28)	return -1;		}	}		return 0;}/* 转化15位身份证到18位 */int id_OldToNew(char * id_old,char * id_new){	char tmp[20];	sscanf(id_old,"%s",id_old);	if (strlen(id_old)!=15)		return -1;	memset(tmp,0x00,sizeof(tmp));	memcpy(tmp,id_old,6);	memcpy(tmp+6,"19",2);	memcpy(tmp+8,id_old+6,9);	memset(id_new,0x00,sizeof(id_new));	strcpy(id_new,tmp);	id_new[17]=GetIdMac(tmp);	id_new[18]=0x00;	return 0;}/* 转化18位身份证回15位 */int id_NewToOld(char * id_new,char * id_old){	char tmp[20];	sscanf(id_new,"%s",tmp);	if (strlen(tmp)!=18) return -1;	memset(id_old,0x00,sizeof(id_old));	memcpy(id_old,tmp,6);	memcpy(id_old+6,tmp+8,9);	id_old[15]=0x00;	return 0;}

⌨️ 快捷键说明

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