📄 ansitime.c
字号:
/* ansiTime.c - ANSI `time' documentation *//* Copyright 1992-2001 Wind River Systems, Inc. *//*modification history--------------------01p,05oct01,dcb Fix SPR 9814, SPR 7736, SPR 62831 and SPR 7191.01o,12mar99,p_m Fixed SPR 8225 by putting asctime output in uppercase.01n,11jul97,dgp doc: SPR 7651 need list of non-reentrant functions01m,20jan97,dbt modified comment for tm_sec (SPR #4436).01l,15oct96,dbt Used reentrant version of ldiv in getTime (fixed SPR #3795).01k,04oct96,dbt reworked the fix for SPR #7277.01j,03oct96,dbt use memcpy with 'strlen + 1' instead of 'strlen' (SPR #7277)01i,12aug96,dbt modified __getTime to treat time_t as an unsigned (SPR #6178).01h,30jul96,dbt In function mktime, if tm_isdst flag is true substract one hour from timeIs (SPR #6954). Updated copyright.01g,25jul96,dbt modified function __jullday (for leap year just test month > 1) modified call to jullday in __getTime in order to give it a year as found in a tm structure, e.g. "96" (SPR #4251) corrected localtime_r (SPR #2521). timeBuffer must be initialized before a call of __getDstInfo. corrected __getDstInfo() (spr 2521) Updated copyright.01h,25jul96,dbt fixed warnings in mktime.c.01g,16feb95,rhp doc tweaks, and synch with subsidiary files01f,15sep94,rhp fixed TIMEZONE example in comment (related to SPR #3490); reduced duplication between man page and comments01e,17aug93,dvs changed TIME to TIMEO to fix conflicting defines (SPR #2249)01d,13mar93,jdi doc tweak.01c,05feb93,jdi doc: clarified TIMEZONE string - SPR 1977; clarified that TIMEZONE is environment variable - SPR 1974.01b,13nov92,dnw changed slong_t decls to long01a,24oct92,smb written.*//* DESCRIPTION The header time.h defines two macros and declares four types and severalfunctions for manipulating time. Many functions deal with a `calendar time'that represents the current date (according to the Gregorian calendar)and time. Some functions deal with `local time', which is the calendartime expressed for some specific time zone, and with Daylight Saving Time,which is a temporary change in the algorithm for determining local time.The local time zone and Daylight Saving Time are implementation-defined..SS MacrosThe macros defined are NULL and:.iP `CLOCKS_PER_SEC' 12the number of ticks per second..LP.SS TypesThe types declared are `size_t' and:.iP "`clock_t', `time_t'" 12arithmetic types capable of representing times..iP "`struct tm'"holds the components of a calendar time in what is known as "broken-down time." The structure contains at least the following members, in any order.The semantics of the members and their normal ranges are expressed in thecomments..TStab(|);l1p9f3 l1 l.int tm_sec; | seconds after the minute | - [0, 59]int tm_min; | minutes after the hour | - [0, 59]int tm_hour; | hours after midnight | - [0, 23]int tm_mday; | day of the month | - [1, 31]int tm_mon; | months since January | - [0, 11]int tm_year; | years since 1900int tm_wday; | days since Sunday | - [0, 6]int tm_yday; | days since January 1 | - [0, 365] int tm_isdst; | Daylight Saving Time flag.TEThe value of `tm_isdst' is positive if Daylight Saving Time is in effect, zeroif Daylight Saving Time is not in effect, and negative if the informationis not available..LPIf the environment variable TIMEZONE is set, the information is retrieved fromthis variable, otherwise from the locale information.TIMEZONE is of the form:.ft CB <name_of_zone>:<(unused)>:<time_in_minutes_from_UTC>:<daylight_start>:<daylight_end>.ft 1To calculate local time, the value of <time_in_minutes_from_UTC> is subtractedfrom UTC; <time_in_minutes_from_UTC> must be positive.Daylight information is expressed as mmddhh (month-day-hour), forexample:.CS UTC::0:040102:100102.CEREENTRANCYWhere there is a pair of routines, such as div() and div_r(), only the routinexxx_r() is reentrant. The xxx() routine is not reentrant. INCLUDE FILES: time.hSEE ALSO: ansiLocale, American National Standard X3.159-1989 *//*Documentation for the ANSI C time library.========================================== Locale Information------------------ The time locale information is stored in the file __timeloc.c. Thisstructure consists of + The days of the week in abbreviated form + The days of the week + Months of the year in abbreviated form + Months of the year + date and time representation for this locale + representation for AM.PM + Time zone information (discussed below ) + Day light saving information (discussed below )If you want to, for example, use the french translation for the daysof the week, then this file could be copied into another filee.g. __frtimeloc.c and the days and months representation in french. Afull compile is neccessary. This means that when using strftime orasctime the days and months will be in French!Maintaining a table of the possible locale variations would mean largelinked lists of tables and is not appropriate for this system.Maybe later we can provide a mechanism for replacing this table by atable defined by the user at system initialisation.The zone and daylight information may also be set to represent thelocal environment.ZONE & Daylight Saving----------------------The first three fields of TIMEZONE are represented in the locale structureby the time zone information area and the day light saving area of thelocale structure is of the same form as the last two fields.The TIMEZONE environment variable can be set by the user to reflect the localeenvironment.SEE ALSO: American National Standard X3.159-1989 NOMANUALINTERNALThis documentation module is built by appending the following files: asctime.c clock.c ctime.c difftime.c gmtime.c localtime.c mktime.c strftime.c time.c*//* asctime.c - asctime file for time.h *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,05feb93,jdi documentation cleanup for 5.1.01b,20sep92,smb documentation additions01a,25jul92,smb written.*//* DESCRIPTION INCLUDE FILE: time.h SEE ALSO: American National Standard X3.159-1989NOMANUAL*/ #include "vxWorks.h"#include "time.h"#include "private/timeP.h"/****************************************************************************** asctime - convert broken-down time into a string (ANSI)** This routine converts the broken-down time pointed to by <timeptr> into a* string of the form:* .CS* SUN SEP 16 01:03:52 1973\en\e0* .CE** This routine is not reentrant. For a reentrant version, see asctime_r().** INCLUDE FILES: time.h** RETURNS: A pointer to the created string.*/char * asctime ( const struct tm *timeptr /* broken-down time */ ) { size_t len = sizeof (ASCBUF); static char asctimeBuf [sizeof (ASCBUF)]; asctime_r (timeptr, asctimeBuf, &len); return (asctimeBuf); }/****************************************************************************** asctime_r - convert broken-down time into a string (POSIX)** This routine converts the broken-down time pointed to by <timeptr> into a* string of the form:* .CS* SUN SEP 16 01:03:52 1973\en\e0* .CE* The string is copied to <asctimeBuf>.** This routine is the POSIX re-entrant version of asctime().** INCLUDE FILES: time.h** RETURNS: The size of the created string.*/int asctime_r ( const struct tm *timeptr, /* broken-down time */ char * asctimeBuf, /* buffer to contain string */ size_t * buflen /* size of buffer */ ) { size_t size; size = strftime (asctimeBuf, *buflen, "%a %b %d %H:%M:%S %Y\n\0", timeptr); return ((int) size); }/* clock.c - clock file for time.h *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01d,05oct01,dcb Fix SPR 9814 and SPR 7736.01c,05feb93,jdi documentation cleanup for 5.1.01b,20sep92,smb documentation additions01a,25jul92,smb written.*//* DESCRIPTION INCLUDE FILE: time.h SEE ALSO: American National Standard X3.159-1989 NOMANUAL*/#include "vxWorks.h"#include "time.h"/******************************************************************************** clock - determine the processor time in use (ANSI)** This routine returns the implementation's best approximation of* the processor time used by the program since the beginning of an* implementation-defined era related only to the program invocation.* To determine the time in seconds, the value returned by clock()* should be divided by the value of the macro CLOCKS_PER_SEC. If the* processor time used is not available or its value cannot be* represented, clock() returns -1.** NOTE:* This routine always returns -1 in VxWorks. VxWorks does not track* per-task time or system idle time. There is no method of determining* how long a task or the entire system has been doing work. tickGet()* can be used to query the number of system ticks since system start.* clock_gettime() can be used to get the current clock time.** INCLUDE FILES: time.h** RETURNS: -1** SEE ALSO: tickGet(), clock_gettime()*/clock_t clock (void) { return ((clock_t) -1); }/* ctime.c - ctime file for time *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01c,05feb93,jdi documentation cleanup for 5.1.01b,20sep92,smb documentation additions01a,25jul92,smb written.*//* DESCRIPTION INCLUDE FILE: time.h SEE ALSO: American National Standard X3.159-1989 NOMANUAL*/#include "vxWorks.h"#include "time.h"#include "private/timeP.h"/********************************************************************************* ctime - convert time in seconds into a string (ANSI)** This routine converts the calendar time pointed to by <timer> into local* time in the form of a string. It is equivalent to:* .CS* asctime (localtime (timer));* .CE** This routine is not reentrant. For a reentrant version, see ctime_r().** INCLUDE FILES: time.h** RETURNS:* The pointer returned by asctime() with local broken-down time as the* argument.** SEE ALSO: asctime(), localtime()*/char * ctime ( const time_t *timer /* calendar time in seconds */ ) { size_t len = sizeof (ASCBUF); static char asctimeBuf [sizeof (ASCBUF)]; return (ctime_r (timer, asctimeBuf, &len)); }/********************************************************************************* ctime_r - convert time in seconds into a string (POSIX)** This routine converts the calendar time pointed to by <timer> into local* time in the form of a string. It is equivalent to:* .CS* asctime (localtime (timer));* .CE** This routine is the POSIX re-entrant version of ctime().** INCLUDE FILES: time.h** RETURNS:* The pointer returned by asctime() with local broken-down time as the* argument.** SEE ALSO: asctime(), localtime()*/char * ctime_r ( const time_t * timer, /* calendar time in seconds */ char * asctimeBuf, /* buffer to contain the string */ size_t * buflen /* size of the buffer */ ) { asctime_r (localtime (timer), asctimeBuf, buflen); return (asctimeBuf); }/* difftime.c - difftime file for time *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01d,04oct01,dcb Fix SPR 7191. Cast time1 and time2 before subtracting.01c,05feb93,jdi documentation cleanup for 5.1.01b,20sep92,smb documentation additions01a,25jul92,smb written.*//* DESCRIPTION INCLUDE FILE: time.h SEE ALSO: American National Standard X3.159-1989 NOMANUAL*/#include "vxWorks.h"#include "time.h"/********************************************************************************* difftime - compute the difference between two calendar times (ANSI)** This routine computes the difference between two calendar times: * <time1> - <time0>.** INCLUDE FILES: time.h** RETURNS: The time difference in seconds, expressed as a double.*/ double difftime ( time_t time1, /* later time, in seconds */ time_t time0 /* earlier time, in seconds */ ) { /* This function assumes that sizeof(time_t) is <= sizeof(double). */ return (double)time1 - (double)time0; }/* gmtime.c - gmtime file for time *//* Copyright 1992-1996 Wind River Systems, Inc. *//*modification history--------------------01g,15oct96,dbt Used reentrant version of ldiv in getTime (fixed SPR #3795).01f,12aug96,dbt modified __getTime to treat time_t as an unsigned (SPR #6178). 01e,21jun96,dbt modified function __jullday (for leap year just test month > 1) modified call to jullday in __getTime in order to give it a year as found in a tm structure, e.g. "96" (SPR #4251) Updated copyright.01f,24aug94,ism fixed problem with bus error in time conversion (SPR #3542) -fixed problem with negative time values -fixed problem with leap year in negative years (SPR #3576)01e,24sep93,jmm __julday() now checks for february 29th as a leap year 01d,05feb93,jdi documentation cleanup for 5.1.01c,13nov92,dnw changed slong_t decls to long01b,20sep92,smb documentation additions01a,25jul92,smb written.*//* DESCRIPTION INCLUDE FILE: time.h, stdlib.h SEE ALSO: American National Standard X3.159-1989 NOMANUAL*/#include "vxWorks.h"#include "time.h"#include "stdlib.h"#include "private/timeP.h"/****************************************************************************** gmtime - convert calendar time into UTC broken-down time (ANSI)** This routine converts the calendar time pointed to by <timer> into* broken-down time, expressed as Coordinated Universal Time (UTC).** This routine is not reentrant. For a reentrant version, see gmtime_r().** INCLUDE FILES: time.h** RETURNS:* A pointer to a broken-down time structure (`tm'), or a null pointer* if UTC is not available.*/struct tm *gmtime ( const time_t *timer /* calendar time in seconds */ ) { static struct tm timeBuffer; gmtime_r (timer, &timeBuffer); return (&timeBuffer); }/****************************************************************************** gmtime_r - convert calendar time into broken-down time (POSIX)** This routine converts the calendar time pointed to by <timer> into* broken-down time, expressed as Coordinated Universal Time (UTC).* The broken-down time is stored in <timeBuffer>.** This routine is the POSIX re-entrant version of gmtime().** INCLUDE FILES: time.h** RETURNS: OK.*/int gmtime_r ( const time_t *timer, /* calendar time in seconds */ struct tm * timeBuffer /* buffer for broken down time */ ) { return (__getTime (*timer, timeBuffer)); }/************************************************************************** __getTime - convert calendar time into broken-down time ** internal routine.** RETURNS: OK* NOMANUAL*/int __getTime (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -