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

📄 strftime.c

📁 vxworks libc库源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    	}    }/********************************************************************************* __weekOfYear - calulate week of year given julian day and week day.** Internal routine* The <start> determins whether the week starts on Sunday or Monday.** RETURNS:	week of year * NOMANUAL*/LOCAL int __weekOfYear    (    int start,  /* either TM_SUNDAY or TM_MONDAY */    int wday,   /* days since sunday */    int yday    /* days since Jan 1 */    )    {    wday = (wday - start + DAYSPERWEEK) % DAYSPERWEEK;    return ((yday - wday + 12) / DAYSPERWEEK - 1);    }/********************************************************************************* __getLocale - determine locale information given an indicator or the*		   type of information needed.** Internal routine** RETURNS: void* NOMANUAL*/LOCAL void __getLocale    (    char *	      buffer,		/* buffer for the string */    int               desc, 		/* descriptor */    const struct tm * tmptr, 		/* broken-down time */    TIMELOCALE *      timeInfo,		/* locale information */    int *             size		/* size of array returned */    )    {    char *	      p = NULL;    char 	      zoneBuf [sizeof (ZONEBUFFER)];    switch(desc)    	{        case DATETIME:    	    p = timeInfo->_Format [DATETIME];             break;        case DATE:    	    p = timeInfo->_Format [DATE];             break;        case TIMEO:    	    p = timeInfo->_Format [TIMEO];             break;        case AMPM:    	    p = timeInfo->_Ampm [(tmptr->tm_hour < 12) ? 0 : 1];            break;        case ZONE:    	    (void) __getZoneInfo (zoneBuf, NAME, timeInfo);	    p = zoneBuf;            break;    	}    *size = strlen (p);    strcpy(buffer, p);    }/********************************************************************************* __intToStr - convert an integer into a string of <sz> size with leading *		  zeroes if neccessary.** Internal routine** RETURNS: void* NOMANUAL*/LOCAL void __intToStr    (    char * buffer,	/* buffer for return string */    int    number,	/* the number to be converted */    int    size		/* size of the string, maximum length of 4 */    )    {    if (number < 0) 	number = 0;    for (buffer += size; 0 <= --size; number /= 10)	{	*--buffer = number % 10 + '0';	}    }/********************************************************************************* __getDay - determine the locale representation of the day of the week** RETURNS: void* NOMANUAL*/LOCAL void __getDay    (    char *       buffer,	/* buffer for return string */    int          index, 	/* integer representation of day of the week */    int          abbr,		/* abbrievation or full spelling */    TIMELOCALE * timeInfo,	/* locale information */    int *        size		/* size of the string returned */    )    {    char *       dayStr;    index += (abbr == ABBR) ? 0 : DAYSPERWEEK;    *size = strlen (dayStr = timeInfo->_Days [index]);    strcpy (buffer, dayStr);    }/********************************************************************************* __getMonth - determine the locale representation of the month of the year ** RETURNS: void* NOMANUAL*/LOCAL void __getMonth    (    char *       buffer,	/* buffer for return string */    int          index, 	/* integer representation of month of year */    int          abbr,		/* abbrievation or full spelling */    TIMELOCALE * timeInfo,	/* locale information */    int *        size		/* size of the string returned */    )    {    char *       monStr;    index += (abbr == ABBR) ? 0 : MONSPERYEAR;    *size = strlen (monStr = timeInfo->_Months [index]);    strcpy (buffer, monStr);    }/********************************************************************************  __getDstInfo - determins whether day light savings is in effect.** TIMEZONE is of the form *     <name of zone>::<time in minutes from UTC>:<daylight start>:<daylight end>**	daylight information is expressed as mmddhh ie. month:day:hour**	e.g. UTC::0:040102:100102** RETURNS: FALSE if not on, TRUE otherwise.* NOMANUAL*/int __getDstInfo	    (    struct tm *  timeNow,     TIMELOCALE * timeInfo    )    {    char *       start = NULL;    char *       end = NULL;    char *       dummy = NULL;    char *       envInfo = NULL;    char *       last = "";    int          monStart = 0;    int          monEnd   = 0;    int          dayStart = 0;    int          dayEnd   = 0;    int          hrStart  = 0;    int          hrEnd    = 0;    char         numstr [4];   /* SPR 28245: changed from 2 to 4 chars */    char         buffer [sizeof (ZONEBUFFER)];    /* Is daylight saving in effect? '0' NO; '>0' YES; '<0' don't know */    /* commented out (SPR #2521)    if (timeNow->tm_isdst != -1)         return (FALSE);    */    /* Is dst information stored in environmental variables */    if ((envInfo = getenv("TIMEZONE")) != NULL)     	{	strcpy (buffer, envInfo);    	dummy = strtok_r (buffer, ":", &last); 			/* next */    	dummy = strtok_r (NULL, ":", &last);   			/* next */    	/* commented out (SPR #2521) *//*     	dummy = strtok_r (NULL, ":", &last);   			/@ next */    	start = strtok_r (NULL, ":", &last); 			/* start time */    	end = strtok_r (NULL, ":", &last);   			/* end time */    	}    else    	{    	/* Is dst information stored in the locale tables */    	start = timeInfo->_Isdst[DSTON];    	end = timeInfo->_Isdst[DSTOFF];    	if ((strcmp (start,"") == 0) || (strcmp (end,"") == 0))    	    return (FALSE);    	}    if ((start == NULL) || (end == NULL))         return (FALSE);    /* analyze the dst information of the form 'mmddhh' */    bzero (numstr, sizeof (numstr));  /* clear numstr before null terminating */    monStart = (atoi (strncpy (numstr, start, 2))) - 1;       	/*start month */    bzero (numstr, sizeof (numstr));  /* clear numstr before null terminating */    monEnd = atoi (strncpy (numstr, end, 2)) - 1;           	/* end month */    if ((timeNow->tm_mon < monStart) || (timeNow->tm_mon > monEnd))     	return (FALSE);    if ((timeNow->tm_mon == monStart) || (timeNow->tm_mon == monEnd))    	{        bzero (numstr, sizeof (numstr));                    /* clear numstr */    	dayStart = atoi (strncpy (numstr, start+2, 2)); 	/* start day */        bzero (numstr, sizeof (numstr));                    /* clear numstr */    	dayEnd = atoi (strncpy (numstr, end+2, 2));     	/* end day */    	if (((timeNow->tm_mon == monStart) && (timeNow->tm_mday < dayStart)) ||     	    ((timeNow->tm_mon == monEnd) && (timeNow->tm_mday > dayEnd)))     	    return (FALSE);    	if (((timeNow->tm_mon == monStart) && (timeNow->tm_mday == dayStart)) ||    	    ((timeNow->tm_mon == monEnd) && (timeNow->tm_mday == dayEnd)))     	    {            bzero (numstr, sizeof (numstr));                /* clear numstr */    	    hrStart = atoi (strncpy (numstr, start+4, 2)); 	/* hour */            bzero (numstr, sizeof (numstr));                /* clear numstr */    	    hrEnd = atoi (strncpy (numstr, end+4, 2));     	/* hour */        /*         * SPR 27606.  DST requires a fallback when the local DST reaches         * the ending hour on the required date.  The timeNow structure         * holds the non-DST corrected time. Hence for the end of DST check         * we assume a DST corrected time (tm_hour+1) and test to see if the         * hour is greater than or *equal* to the ending hour         */    	    return ((((timeNow->tm_mon==monStart) &&    		     (timeNow->tm_mday==dayStart) &&    		     (timeNow->tm_hour < hrStart)) ||    		    ((timeNow->tm_mon == monEnd) &&    		     (timeNow->tm_mday==dayEnd) &&                 ((timeNow->tm_hour+1) >= hrEnd)))  /* SPR 27606 */    		   ? FALSE : TRUE);    	    }    	}    return (TRUE);    }/********************************************************************************  __getZoneInfo - determins in minutes the time difference from UTC.** If the environment variable TIMEZONE is set then the information is* retrieved from this variable, otherwise from the locale information.** RETURNS: time in minutes from UTC.* NOMANUAL*/void __getZoneInfo    (    char *       buffer,    int          option, 	/* determine which part of zone information */    TIMELOCALE * timeInfo	/* locale information */    )    {    char *       envInfo;    char *       limitStartPtr;    char *       limitEndPtr;    /* Time zone information from the environment variable */    envInfo = getenv ("TIMEZONE");     if ((envInfo != NULL) && (strcmp (envInfo, "") != 0))     	{	limitEndPtr = strpbrk (envInfo, ":");	if (option == NAME)	    {	    strcpy (buffer, envInfo);	    *(buffer + (limitEndPtr - envInfo)) = EOS;	    return;	    }	limitStartPtr = limitEndPtr + 1;	limitEndPtr = strpbrk (limitStartPtr, ":"); 	if (option == NAME2)	    {	    strcpy (buffer, limitStartPtr);	    *(buffer + (limitEndPtr - limitStartPtr)) = EOS;	    return;	    }	limitStartPtr = limitEndPtr + 1;	limitEndPtr = strpbrk (limitStartPtr, ":"); 	if (option == TIMEOFFSET)	    {	    strcpy (buffer, limitStartPtr);	    if (limitEndPtr != NULL)	        *(buffer + (limitEndPtr - limitStartPtr)) = EOS;	    return;	    }    	}    else	{        /* Time zone information from the locale table */        if (strcmp (timeInfo->_Zone [option], "") != 0)	    strcpy(buffer,timeInfo->_Zone [option]);        else	             *buffer = EOS;        }    }

⌨️ 快捷键说明

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