auto import //branches/master/...@140412

This commit is contained in:
The Android Open Source Project 2009-03-18 22:20:24 -07:00
parent 78bf5fc677
commit edbe7fc97b
9 changed files with 2654 additions and 2690 deletions

View File

@ -63,6 +63,18 @@ time_t:
Instead, Bionic provides a <time64.h> header that defines a time64_t type, Instead, Bionic provides a <time64.h> header that defines a time64_t type,
and related functions like mktime64(), localtime64(), etc... and related functions like mktime64(), localtime64(), etc...
strftime() uses time64_t internally, so the '%s' format (seconds since the
epoch) is supported for dates >= 2038.
strftime_tz():
Bionic also provides the non-standard strftime_tz() function, a variant
of strftime() which also accepts a time locale descriptor as defined
by "struct strftime_locale" in <time.h>.
This function is used by the low-level framework code in Android.
Timezone management: Timezone management:

View File

@ -79,9 +79,28 @@ extern struct tm* gmtime_r(const time_t *timep, struct tm *result);
extern char* strptime(const char *buf, const char *fmt, struct tm *tm); extern char* strptime(const char *buf, const char *fmt, struct tm *tm);
extern size_t strftime(char *s, size_t max, const char *format, const struct tm *tm); extern size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
/* ANDROID-BEGIN */
struct strftime_locale {
const char * mon[12];
const char * month[12];
const char * wday[7];
const char * weekday[7];
const char * X_fmt;
const char * x_fmt;
const char * c_fmt;
const char * am;
const char * pm;
const char * date_fmt;
};
extern size_t strftime_tz(char *s, size_t max, const char *format, const struct tm *tm, const struct strftime_locale* lc);
/* ANDROID-END */
extern char *ctime(const time_t *timep); extern char *ctime(const time_t *timep);
extern char *ctime_r(const time_t *timep, char *buf); extern char *ctime_r(const time_t *timep, char *buf);
extern void tzset(void);
/* global includes */ /* global includes */
extern char* tzname[]; extern char* tzname[];
extern int daylight; extern int daylight;

View File

@ -11,7 +11,7 @@
#ifndef lint #ifndef lint
#ifndef NOID #ifndef NOID
static char elsieid[] = "@(#)asctime.c 8.2"; static char elsieid[] = "@(#)asctime.c 8.2";
#endif /* !defined NOID */ #endif /* !defined NOID */
#endif /* !defined lint */ #endif /* !defined lint */
@ -39,9 +39,9 @@ static char elsieid[] = "@(#)asctime.c 8.2";
** but many implementations pad anyway; most likely the standards are buggy. ** but many implementations pad anyway; most likely the standards are buggy.
*/ */
#ifdef __GNUC__ #ifdef __GNUC__
#define ASCTIME_FMT "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %-4s\n" #define ASCTIME_FMT "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %-4s\n"
#else /* !defined __GNUC__ */ #else /* !defined __GNUC__ */
#define ASCTIME_FMT "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n" #define ASCTIME_FMT "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n"
#endif /* !defined __GNUC__ */ #endif /* !defined __GNUC__ */
/* /*
** For years that are more than four digits we put extra spaces before the year ** For years that are more than four digits we put extra spaces before the year
@ -50,12 +50,12 @@ static char elsieid[] = "@(#)asctime.c 8.2";
** that no output is better than wrong output). ** that no output is better than wrong output).
*/ */
#ifdef __GNUC__ #ifdef __GNUC__
#define ASCTIME_FMT_B "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %s\n" #define ASCTIME_FMT_B "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %s\n"
#else /* !defined __GNUC__ */ #else /* !defined __GNUC__ */
#define ASCTIME_FMT_B "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %s\n" #define ASCTIME_FMT_B "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %s\n"
#endif /* !defined __GNUC__ */ #endif /* !defined __GNUC__ */
#define STD_ASCTIME_BUF_SIZE 26 #define STD_ASCTIME_BUF_SIZE 26
/* /*
** Big enough for something such as ** Big enough for something such as
** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
@ -66,9 +66,9 @@ static char elsieid[] = "@(#)asctime.c 8.2";
** as an example; the define below calculates the maximum for the system at ** as an example; the define below calculates the maximum for the system at
** hand. ** hand.
*/ */
#define MAX_ASCTIME_BUF_SIZE (2*3+5*INT_STRLEN_MAXIMUM(int)+7+2+1+1) #define MAX_ASCTIME_BUF_SIZE (2*3+5*INT_STRLEN_MAXIMUM(int)+7+2+1+1)
static char buf_asctime[MAX_ASCTIME_BUF_SIZE]; static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
/* /*
** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, 2004 Edition. ** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, 2004 Edition.
@ -76,54 +76,54 @@ static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
char * char *
asctime_r(timeptr, buf) asctime_r(timeptr, buf)
register const struct tm * timeptr; register const struct tm * timeptr;
char * buf; char * buf;
{ {
static const char wday_name[][3] = { static const char wday_name[][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
}; };
static const char mon_name[][3] = { static const char mon_name[][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}; };
register const char * wn; register const char * wn;
register const char * mn; register const char * mn;
char year[INT_STRLEN_MAXIMUM(int) + 2]; char year[INT_STRLEN_MAXIMUM(int) + 2];
char result[MAX_ASCTIME_BUF_SIZE]; char result[MAX_ASCTIME_BUF_SIZE];
if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
wn = "???"; wn = "???";
else wn = wday_name[timeptr->tm_wday]; else wn = wday_name[timeptr->tm_wday];
if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
mn = "???"; mn = "???";
else mn = mon_name[timeptr->tm_mon]; else mn = mon_name[timeptr->tm_mon];
/* /*
** Use strftime's %Y to generate the year, to avoid overflow problems ** Use strftime's %Y to generate the year, to avoid overflow problems
** when computing timeptr->tm_year + TM_YEAR_BASE. ** when computing timeptr->tm_year + TM_YEAR_BASE.
** Assume that strftime is unaffected by other out-of-range members ** Assume that strftime is unaffected by other out-of-range members
** (e.g., timeptr->tm_mday) when processing "%Y". ** (e.g., timeptr->tm_mday) when processing "%Y".
*/ */
(void) strftime(year, sizeof year, "%Y", timeptr); (void) strftime(year, sizeof year, "%Y", timeptr);
/* /*
** We avoid using snprintf since it's not available on all systems. ** We avoid using snprintf since it's not available on all systems.
*/ */
(void) sprintf(result, (void) sprintf(result,
((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B), ((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B),
wn, mn, wn, mn,
timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_mday, timeptr->tm_hour,
timeptr->tm_min, timeptr->tm_sec, timeptr->tm_min, timeptr->tm_sec,
year); year);
if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime) { if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime) {
(void) strcpy(buf, result); (void) strcpy(buf, result);
return buf; return buf;
} else { } else {
#ifdef EOVERFLOW #ifdef EOVERFLOW
errno = EOVERFLOW; errno = EOVERFLOW;
#else /* !defined EOVERFLOW */ #else /* !defined EOVERFLOW */
errno = EINVAL; errno = EINVAL;
#endif /* !defined EOVERFLOW */ #endif /* !defined EOVERFLOW */
return NULL; return NULL;
} }
} }
/* /*
@ -132,7 +132,7 @@ char * buf;
char * char *
asctime(timeptr) asctime(timeptr)
register const struct tm * timeptr; register const struct tm * timeptr;
{ {
return asctime_r(timeptr, buf_asctime); return asctime_r(timeptr, buf_asctime);
} }

View File

@ -5,61 +5,61 @@
#ifndef lint #ifndef lint
#ifndef NOID #ifndef NOID
static char elsieid[] = "@(#)difftime.c 8.1"; static char elsieid[] = "@(#)difftime.c 8.1";
#endif /* !defined NOID */ #endif /* !defined NOID */
#endif /* !defined lint */ #endif /* !defined lint */
/*LINTLIBRARY*/ /*LINTLIBRARY*/
#include "private.h" /* for time_t, TYPE_INTEGRAL, and TYPE_SIGNED */ #include "private.h" /* for time_t, TYPE_INTEGRAL, and TYPE_SIGNED */
double double
difftime(time1, time0) difftime(time1, time0)
const time_t time1; const time_t time1;
const time_t time0; const time_t time0;
{ {
/* /*
** If (sizeof (double) > sizeof (time_t)) simply convert and subtract ** If (sizeof (double) > sizeof (time_t)) simply convert and subtract
** (assuming that the larger type has more precision). ** (assuming that the larger type has more precision).
** This is the common real-world case circa 2004. ** This is the common real-world case circa 2004.
*/ */
if (sizeof (double) > sizeof (time_t)) if (sizeof (double) > sizeof (time_t))
return (double) time1 - (double) time0; return (double) time1 - (double) time0;
if (!TYPE_INTEGRAL(time_t)) { if (!TYPE_INTEGRAL(time_t)) {
/* /*
** time_t is floating. ** time_t is floating.
*/ */
return time1 - time0; return time1 - time0;
} }
if (!TYPE_SIGNED(time_t)) { if (!TYPE_SIGNED(time_t)) {
/* /*
** time_t is integral and unsigned. ** time_t is integral and unsigned.
** The difference of two unsigned values can't overflow ** The difference of two unsigned values can't overflow
** if the minuend is greater than or equal to the subtrahend. ** if the minuend is greater than or equal to the subtrahend.
*/ */
if (time1 >= time0) if (time1 >= time0)
return time1 - time0; return time1 - time0;
else return -((double) (time0 - time1)); else return -((double) (time0 - time1));
} }
/* /*
** time_t is integral and signed. ** time_t is integral and signed.
** Handle cases where both time1 and time0 have the same sign ** Handle cases where both time1 and time0 have the same sign
** (meaning that their difference cannot overflow). ** (meaning that their difference cannot overflow).
*/ */
if ((time1 < 0) == (time0 < 0)) if ((time1 < 0) == (time0 < 0))
return time1 - time0; return time1 - time0;
/* /*
** time1 and time0 have opposite signs. ** time1 and time0 have opposite signs.
** Punt if unsigned long is too narrow. ** Punt if unsigned long is too narrow.
*/ */
if (sizeof (unsigned long) < sizeof (time_t)) if (sizeof (unsigned long) < sizeof (time_t))
return (double) time1 - (double) time0; return (double) time1 - (double) time0;
/* /*
** Stay calm...decent optimizers will eliminate the complexity below. ** Stay calm...decent optimizers will eliminate the complexity below.
*/ */
if (time1 >= 0 /* && time0 < 0 */) if (time1 >= 0 /* && time0 < 0 */)
return (unsigned long) time1 + return (unsigned long) time1 +
(unsigned long) (-(time0 + 1)) + 1; (unsigned long) (-(time0 + 1)) + 1;
return -(double) ((unsigned long) time0 + return -(double) ((unsigned long) time0 +
(unsigned long) (-(time1 + 1)) + 1); (unsigned long) (-(time1 + 1)) + 1);
} }

File diff suppressed because it is too large Load Diff

View File

@ -21,11 +21,11 @@
#ifndef lint #ifndef lint
#ifndef NOID #ifndef NOID
static char privatehid[] = "@(#)private.h 8.2"; static char privatehid[] = "@(#)private.h 8.2";
#endif /* !defined NOID */ #endif /* !defined NOID */
#endif /* !defined lint */ #endif /* !defined lint */
#define GRANDPARENTED "Local time zone must be set--see zic manual page" #define GRANDPARENTED "Local time zone must be set--see zic manual page"
/* /*
** Defaults for preprocessor symbols. ** Defaults for preprocessor symbols.
@ -33,49 +33,45 @@ static char privatehid[] = "@(#)private.h 8.2";
*/ */
#ifndef HAVE_ADJTIME #ifndef HAVE_ADJTIME
#define HAVE_ADJTIME 1 #define HAVE_ADJTIME 1
#endif /* !defined HAVE_ADJTIME */ #endif /* !defined HAVE_ADJTIME */
#ifndef HAVE_GETTEXT #ifndef HAVE_GETTEXT
#define HAVE_GETTEXT 0 #define HAVE_GETTEXT 0
#endif /* !defined HAVE_GETTEXT */ #endif /* !defined HAVE_GETTEXT */
#ifndef HAVE_INCOMPATIBLE_CTIME_R #ifndef HAVE_INCOMPATIBLE_CTIME_R
#define HAVE_INCOMPATIBLE_CTIME_R 0 #define HAVE_INCOMPATIBLE_CTIME_R 0
#endif /* !defined INCOMPATIBLE_CTIME_R */ #endif /* !defined INCOMPATIBLE_CTIME_R */
#ifndef HAVE_SETTIMEOFDAY #ifndef HAVE_SETTIMEOFDAY
#define HAVE_SETTIMEOFDAY 3 #define HAVE_SETTIMEOFDAY 3
#endif /* !defined HAVE_SETTIMEOFDAY */ #endif /* !defined HAVE_SETTIMEOFDAY */
#ifndef HAVE_STRERROR #ifndef HAVE_STRERROR
#define HAVE_STRERROR 1 #define HAVE_STRERROR 1
#endif /* !defined HAVE_STRERROR */ #endif /* !defined HAVE_STRERROR */
#ifndef HAVE_SYMLINK #ifndef HAVE_SYMLINK
#define HAVE_SYMLINK 1 #define HAVE_SYMLINK 1
#endif /* !defined HAVE_SYMLINK */ #endif /* !defined HAVE_SYMLINK */
#ifndef HAVE_SYS_STAT_H #ifndef HAVE_SYS_STAT_H
#define HAVE_SYS_STAT_H 1 #define HAVE_SYS_STAT_H 1
#endif /* !defined HAVE_SYS_STAT_H */ #endif /* !defined HAVE_SYS_STAT_H */
#ifndef HAVE_SYS_WAIT_H #ifndef HAVE_SYS_WAIT_H
#define HAVE_SYS_WAIT_H 1 #define HAVE_SYS_WAIT_H 1
#endif /* !defined HAVE_SYS_WAIT_H */ #endif /* !defined HAVE_SYS_WAIT_H */
#ifndef HAVE_UNISTD_H #ifndef HAVE_UNISTD_H
#define HAVE_UNISTD_H 1 #define HAVE_UNISTD_H 1
#endif /* !defined HAVE_UNISTD_H */ #endif /* !defined HAVE_UNISTD_H */
#ifndef HAVE_UTMPX_H #ifndef HAVE_UTMPX_H
#define HAVE_UTMPX_H 0 #define HAVE_UTMPX_H 0
#endif /* !defined HAVE_UTMPX_H */ #endif /* !defined HAVE_UTMPX_H */
#ifndef LOCALE_HOME
#define LOCALE_HOME "/usr/lib/locale"
#endif /* !defined LOCALE_HOME */
#if HAVE_INCOMPATIBLE_CTIME_R #if HAVE_INCOMPATIBLE_CTIME_R
#define asctime_r _incompatible_asctime_r #define asctime_r _incompatible_asctime_r
#define ctime_r _incompatible_ctime_r #define ctime_r _incompatible_ctime_r
@ -85,11 +81,11 @@ static char privatehid[] = "@(#)private.h 8.2";
** Nested includes ** Nested includes
*/ */
#include "sys/types.h" /* for time_t */ #include "sys/types.h" /* for time_t */
#include "stdio.h" #include "stdio.h"
#include "errno.h" #include "errno.h"
#include "string.h" #include "string.h"
#include "limits.h" /* for CHAR_BIT et al. */ #include "limits.h" /* for CHAR_BIT et al. */
#include "time.h" #include "time.h"
#include "stdlib.h" #include "stdlib.h"
@ -98,26 +94,26 @@ static char privatehid[] = "@(#)private.h 8.2";
#endif /* HAVE_GETTEXT */ #endif /* HAVE_GETTEXT */
#if HAVE_SYS_WAIT_H #if HAVE_SYS_WAIT_H
#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */ #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
#endif /* HAVE_SYS_WAIT_H */ #endif /* HAVE_SYS_WAIT_H */
#ifndef WIFEXITED #ifndef WIFEXITED
#define WIFEXITED(status) (((status) & 0xff) == 0) #define WIFEXITED(status) (((status) & 0xff) == 0)
#endif /* !defined WIFEXITED */ #endif /* !defined WIFEXITED */
#ifndef WEXITSTATUS #ifndef WEXITSTATUS
#define WEXITSTATUS(status) (((status) >> 8) & 0xff) #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
#endif /* !defined WEXITSTATUS */ #endif /* !defined WEXITSTATUS */
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include "unistd.h" /* for F_OK and R_OK */ #include "unistd.h" /* for F_OK and R_OK */
#endif /* HAVE_UNISTD_H */ #endif /* HAVE_UNISTD_H */
#if !HAVE_UNISTD_H #if !HAVE_UNISTD_H
#ifndef F_OK #ifndef F_OK
#define F_OK 0 #define F_OK 0
#endif /* !defined F_OK */ #endif /* !defined F_OK */
#ifndef R_OK #ifndef R_OK
#define R_OK 4 #define R_OK 4
#endif /* !defined R_OK */ #endif /* !defined R_OK */
#endif /* !HAVE_UNISTD_H */ #endif /* !HAVE_UNISTD_H */
@ -132,8 +128,8 @@ static char privatehid[] = "@(#)private.h 8.2";
*/ */
#ifndef HAVE_STDINT_H #ifndef HAVE_STDINT_H
#define HAVE_STDINT_H \ #define HAVE_STDINT_H \
(199901 <= __STDC_VERSION__ || \ (199901 <= __STDC_VERSION__ || \
2 < (__GLIBC__ + (0 < __GLIBC_MINOR__))) 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
#endif /* !defined HAVE_STDINT_H */ #endif /* !defined HAVE_STDINT_H */
#if HAVE_STDINT_H #if HAVE_STDINT_H
@ -143,13 +139,13 @@ static char privatehid[] = "@(#)private.h 8.2";
#ifndef INT_FAST64_MAX #ifndef INT_FAST64_MAX
/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */ /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
#if defined LLONG_MAX || defined __LONG_LONG_MAX__ #if defined LLONG_MAX || defined __LONG_LONG_MAX__
typedef long long int_fast64_t; typedef long long int_fast64_t;
#else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
#if (LONG_MAX >> 31) < 0xffffffff #if (LONG_MAX >> 31) < 0xffffffff
Please use a compiler that supports a 64-bit integer type (or wider); Please use a compiler that supports a 64-bit integer type (or wider);
you may need to compile with "-DHAVE_STDINT_H". you may need to compile with "-DHAVE_STDINT_H".
#endif /* (LONG_MAX >> 31) < 0xffffffff */ #endif /* (LONG_MAX >> 31) < 0xffffffff */
typedef long int_fast64_t; typedef long int_fast64_t;
#endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */ #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
#endif /* !defined INT_FAST64_MAX */ #endif /* !defined INT_FAST64_MAX */
@ -169,7 +165,7 @@ typedef long int_fast64_t;
*/ */
#ifndef P #ifndef P
#define P(x) x #define P(x) x
#endif /* !defined P */ #endif /* !defined P */
/* /*
@ -177,7 +173,7 @@ typedef long int_fast64_t;
*/ */
#ifndef EXIT_SUCCESS #ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0
#endif /* !defined EXIT_SUCCESS */ #endif /* !defined EXIT_SUCCESS */
/* /*
@ -185,7 +181,7 @@ typedef long int_fast64_t;
*/ */
#ifndef EXIT_FAILURE #ifndef EXIT_FAILURE
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif /* !defined EXIT_FAILURE */ #endif /* !defined EXIT_FAILURE */
/* /*
@ -201,10 +197,10 @@ typedef long int_fast64_t;
#endif /* !defined MAXPATHLEN */ #endif /* !defined MAXPATHLEN */
#ifdef MAXPATHLEN #ifdef MAXPATHLEN
#define FILENAME_MAX MAXPATHLEN #define FILENAME_MAX MAXPATHLEN
#endif /* defined MAXPATHLEN */ #endif /* defined MAXPATHLEN */
#ifndef MAXPATHLEN #ifndef MAXPATHLEN
#define FILENAME_MAX 1024 /* Pure guesswork */ #define FILENAME_MAX 1024 /* Pure guesswork */
#endif /* !defined MAXPATHLEN */ #endif /* !defined MAXPATHLEN */
#endif /* !defined FILENAME_MAX */ #endif /* !defined FILENAME_MAX */
@ -214,8 +210,8 @@ typedef long int_fast64_t;
*/ */
#ifndef remove #ifndef remove
extern int unlink P((const char * filename)); extern int unlink P((const char * filename));
#define remove unlink #define remove unlink
#endif /* !defined remove */ #endif /* !defined remove */
/* /*
@ -235,36 +231,36 @@ extern int errno;
*/ */
#ifndef asctime_r #ifndef asctime_r
extern char * asctime_r(); extern char * asctime_r();
#endif #endif
/* /*
** Private function declarations. ** Private function declarations.
*/ */
char * icalloc P((int nelem, int elsize)); char * icalloc P((int nelem, int elsize));
char * icatalloc P((char * old, const char * new)); char * icatalloc P((char * old, const char * new));
char * icpyalloc P((const char * string)); char * icpyalloc P((const char * string));
char * imalloc P((int n)); char * imalloc P((int n));
void * irealloc P((void * pointer, int size)); void * irealloc P((void * pointer, int size));
void icfree P((char * pointer)); void icfree P((char * pointer));
void ifree P((char * pointer)); void ifree P((char * pointer));
const char * scheck P((const char * string, const char * format)); const char * scheck P((const char * string, const char * format));
/* /*
** Finally, some convenience items. ** Finally, some convenience items.
*/ */
#ifndef TRUE #ifndef TRUE
#define TRUE 1 #define TRUE 1
#endif /* !defined TRUE */ #endif /* !defined TRUE */
#ifndef FALSE #ifndef FALSE
#define FALSE 0 #define FALSE 0
#endif /* !defined FALSE */ #endif /* !defined FALSE */
#ifndef TYPE_BIT #ifndef TYPE_BIT
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
#endif /* !defined TYPE_BIT */ #endif /* !defined TYPE_BIT */
#ifndef TYPE_SIGNED #ifndef TYPE_SIGNED
@ -288,8 +284,8 @@ const char * scheck P((const char * string, const char * format));
** add one more for a minus sign if the type is signed. ** add one more for a minus sign if the type is signed.
*/ */
#define INT_STRLEN_MAXIMUM(type) \ #define INT_STRLEN_MAXIMUM(type) \
((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \ ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
1 + TYPE_SIGNED(type)) 1 + TYPE_SIGNED(type))
#endif /* !defined INT_STRLEN_MAXIMUM */ #endif /* !defined INT_STRLEN_MAXIMUM */
/* /*
@ -309,7 +305,7 @@ const char * scheck P((const char * string, const char * format));
#ifndef INITIALIZE #ifndef INITIALIZE
#ifdef GNUC_or_lint #ifdef GNUC_or_lint
#define INITIALIZE(x) ((x) = 0) #define INITIALIZE(x) ((x) = 0)
#endif /* defined GNUC_or_lint */ #endif /* defined GNUC_or_lint */
#ifndef GNUC_or_lint #ifndef GNUC_or_lint
#define INITIALIZE(x) #define INITIALIZE(x)
@ -342,7 +338,7 @@ char *ctime_r P((time_t const *, char *));
#endif /* HAVE_INCOMPATIBLE_CTIME_R */ #endif /* HAVE_INCOMPATIBLE_CTIME_R */
#ifndef YEARSPERREPEAT #ifndef YEARSPERREPEAT
#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
#endif /* !defined YEARSPERREPEAT */ #endif /* !defined YEARSPERREPEAT */
/* /*
@ -350,15 +346,15 @@ char *ctime_r P((time_t const *, char *));
*/ */
#ifndef AVGSECSPERYEAR #ifndef AVGSECSPERYEAR
#define AVGSECSPERYEAR 31556952L #define AVGSECSPERYEAR 31556952L
#endif /* !defined AVGSECSPERYEAR */ #endif /* !defined AVGSECSPERYEAR */
#ifndef SECSPERREPEAT #ifndef SECSPERREPEAT
#define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR) #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
#endif /* !defined SECSPERREPEAT */ #endif /* !defined SECSPERREPEAT */
#ifndef SECSPERREPEAT_BITS #ifndef SECSPERREPEAT_BITS
#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
#endif /* !defined SECSPERREPEAT_BITS */ #endif /* !defined SECSPERREPEAT_BITS */
/* /*

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* $OpenBSD: strptime.c,v 1.11 2005/08/08 08:05:38 espie Exp $ */ /* $OpenBSD: strptime.c,v 1.11 2005/08/08 08:05:38 espie Exp $ */
/* $NetBSD: strptime.c,v 1.12 1998/01/20 21:39:40 mycroft Exp $ */ /* $NetBSD: strptime.c,v 1.12 1998/01/20 21:39:40 mycroft Exp $ */
/*- /*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -44,387 +44,387 @@
#include "tzfile.h" #include "tzfile.h"
static const struct { static const struct {
const char *abday[7]; const char *abday[7];
const char *day[7]; const char *day[7];
const char *abmon[12]; const char *abmon[12];
const char *mon[12]; const char *mon[12];
const char *am_pm[2]; const char *am_pm[2];
const char *d_t_fmt; const char *d_t_fmt;
const char *d_fmt; const char *d_fmt;
const char *t_fmt; const char *t_fmt;
const char *t_fmt_ampm; const char *t_fmt_ampm;
} _DefaultTimeLocale = { } _DefaultTimeLocale = {
{ {
"Sun","Mon","Tue","Wed","Thu","Fri","Sat", "Sun","Mon","Tue","Wed","Thu","Fri","Sat",
}, },
{ {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday" "Friday", "Saturday"
}, },
{ {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}, },
{ {
"January", "February", "March", "April", "May", "June", "July", "January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December" "August", "September", "October", "November", "December"
}, },
{ {
"AM", "PM" "AM", "PM"
}, },
"%a %b %d %H:%M:%S %Y", "%a %b %d %H:%M:%S %Y",
"%m/%d/%y", "%m/%d/%y",
"%H:%M:%S", "%H:%M:%S",
"%I:%M:%S %p" "%I:%M:%S %p"
}; };
#define _ctloc(x) (_DefaultTimeLocale.x) #define _ctloc(x) (_DefaultTimeLocale.x)
/* /*
* We do not implement alternate representations. However, we always * We do not implement alternate representations. However, we always
* check whether a given modifier is allowed for a certain conversion. * check whether a given modifier is allowed for a certain conversion.
*/ */
#define _ALT_E 0x01 #define _ALT_E 0x01
#define _ALT_O 0x02 #define _ALT_O 0x02
#define _LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); } #define _LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
static int _conv_num(const unsigned char **, int *, int, int); static int _conv_num(const unsigned char **, int *, int, int);
static char *_strptime(const char *, const char *, struct tm *, int); static unsigned char *_strptime(const unsigned char *, const char *, struct tm *, int);
char * char *
strptime(const char *buf, const char *fmt, struct tm *tm) strptime(const char *buf, const char *fmt, struct tm *tm)
{ {
return(_strptime(buf, fmt, tm, 1)); return (char*)(_strptime((const unsigned char*)buf, fmt, tm, 1));
} }
static char * static unsigned char *
_strptime(const char *buf, const char *fmt, struct tm *tm, int initialize) _strptime(const unsigned char *buf, const char *fmt, struct tm *tm, int initialize)
{ {
unsigned char c; unsigned char c;
const unsigned char *bp; const unsigned char *bp;
size_t len; size_t len = 0;
int alt_format, i; int alt_format, i;
static int century, relyear; static int century, relyear;
if (initialize) { if (initialize) {
century = TM_YEAR_BASE; century = TM_YEAR_BASE;
relyear = -1; relyear = -1;
} }
bp = (unsigned char *)buf; bp = (unsigned char *)buf;
while ((c = *fmt) != '\0') { while ((c = *fmt) != '\0') {
/* Clear `alternate' modifier prior to new conversion. */ /* Clear `alternate' modifier prior to new conversion. */
alt_format = 0; alt_format = 0;
/* Eat up white-space. */ /* Eat up white-space. */
if (isspace(c)) { if (isspace(c)) {
while (isspace(*bp)) while (isspace(*bp))
bp++; bp++;
fmt++; fmt++;
continue; continue;
} }
if ((c = *fmt++) != '%') if ((c = *fmt++) != '%')
goto literal; goto literal;
again: switch (c = *fmt++) { again: switch (c = *fmt++) {
case '%': /* "%%" is converted to "%". */ case '%': /* "%%" is converted to "%". */
literal: literal:
if (c != *bp++) if (c != *bp++)
return (NULL); return (NULL);
break; break;
/* /*
* "Alternative" modifiers. Just set the appropriate flag * "Alternative" modifiers. Just set the appropriate flag
* and start over again. * and start over again.
*/ */
case 'E': /* "%E?" alternative conversion modifier. */ case 'E': /* "%E?" alternative conversion modifier. */
_LEGAL_ALT(0); _LEGAL_ALT(0);
alt_format |= _ALT_E; alt_format |= _ALT_E;
goto again; goto again;
case 'O': /* "%O?" alternative conversion modifier. */ case 'O': /* "%O?" alternative conversion modifier. */
_LEGAL_ALT(0); _LEGAL_ALT(0);
alt_format |= _ALT_O; alt_format |= _ALT_O;
goto again; goto again;
/* /*
* "Complex" conversion rules, implemented through recursion. * "Complex" conversion rules, implemented through recursion.
*/ */
case 'c': /* Date and time, using the locale's format. */ case 'c': /* Date and time, using the locale's format. */
_LEGAL_ALT(_ALT_E); _LEGAL_ALT(_ALT_E);
if (!(bp = _strptime(bp, _ctloc(d_t_fmt), tm, 0))) if (!(bp = _strptime(bp, _ctloc(d_t_fmt), tm, 0)))
return (NULL); return (NULL);
break; break;
case 'D': /* The date as "%m/%d/%y". */ case 'D': /* The date as "%m/%d/%y". */
_LEGAL_ALT(0); _LEGAL_ALT(0);
if (!(bp = _strptime(bp, "%m/%d/%y", tm, 0))) if (!(bp = _strptime(bp, "%m/%d/%y", tm, 0)))
return (NULL); return (NULL);
break; break;
case 'R': /* The time as "%H:%M". */ case 'R': /* The time as "%H:%M". */
_LEGAL_ALT(0); _LEGAL_ALT(0);
if (!(bp = _strptime(bp, "%H:%M", tm, 0))) if (!(bp = _strptime(bp, "%H:%M", tm, 0)))
return (NULL); return (NULL);
break; break;
case 'r': /* The time as "%I:%M:%S %p". */ case 'r': /* The time as "%I:%M:%S %p". */
_LEGAL_ALT(0); _LEGAL_ALT(0);
if (!(bp = _strptime(bp, "%I:%M:%S %p", tm, 0))) if (!(bp = _strptime(bp, "%I:%M:%S %p", tm, 0)))
return (NULL); return (NULL);
break; break;
case 'T': /* The time as "%H:%M:%S". */ case 'T': /* The time as "%H:%M:%S". */
_LEGAL_ALT(0); _LEGAL_ALT(0);
if (!(bp = _strptime(bp, "%H:%M:%S", tm, 0))) if (!(bp = _strptime(bp, "%H:%M:%S", tm, 0)))
return (NULL); return (NULL);
break; break;
case 'X': /* The time, using the locale's format. */ case 'X': /* The time, using the locale's format. */
_LEGAL_ALT(_ALT_E); _LEGAL_ALT(_ALT_E);
if (!(bp = _strptime(bp, _ctloc(t_fmt), tm, 0))) if (!(bp = _strptime(bp, _ctloc(t_fmt), tm, 0)))
return (NULL); return (NULL);
break; break;
case 'x': /* The date, using the locale's format. */ case 'x': /* The date, using the locale's format. */
_LEGAL_ALT(_ALT_E); _LEGAL_ALT(_ALT_E);
if (!(bp = _strptime(bp, _ctloc(d_fmt), tm, 0))) if (!(bp = _strptime(bp, _ctloc(d_fmt), tm, 0)))
return (NULL); return (NULL);
break; break;
/* /*
* "Elementary" conversion rules. * "Elementary" conversion rules.
*/ */
case 'A': /* The day of week, using the locale's form. */ case 'A': /* The day of week, using the locale's form. */
case 'a': case 'a':
_LEGAL_ALT(0); _LEGAL_ALT(0);
for (i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
/* Full name. */ /* Full name. */
len = strlen(_ctloc(day[i])); len = strlen(_ctloc(day[i]));
if (strncasecmp(_ctloc(day[i]), bp, len) == 0) if (strncasecmp(_ctloc(day[i]), (const char*)bp, len) == 0)
break; break;
/* Abbreviated name. */ /* Abbreviated name. */
len = strlen(_ctloc(abday[i])); len = strlen(_ctloc(abday[i]));
if (strncasecmp(_ctloc(abday[i]), bp, len) == 0) if (strncasecmp(_ctloc(abday[i]), (const char*)bp, len) == 0)
break; break;
} }
/* Nothing matched. */ /* Nothing matched. */
if (i == 7) if (i == 7)
return (NULL); return (NULL);
tm->tm_wday = i; tm->tm_wday = i;
bp += len; bp += len;
break; break;
case 'B': /* The month, using the locale's form. */ case 'B': /* The month, using the locale's form. */
case 'b': case 'b':
case 'h': case 'h':
_LEGAL_ALT(0); _LEGAL_ALT(0);
for (i = 0; i < 12; i++) { for (i = 0; i < 12; i++) {
/* Full name. */ /* Full name. */
len = strlen(_ctloc(mon[i])); len = strlen(_ctloc(mon[i]));
if (strncasecmp(_ctloc(mon[i]), bp, len) == 0) if (strncasecmp(_ctloc(mon[i]), (const char*)bp, len) == 0)
break; break;
/* Abbreviated name. */ /* Abbreviated name. */
len = strlen(_ctloc(abmon[i])); len = strlen(_ctloc(abmon[i]));
if (strncasecmp(_ctloc(abmon[i]), bp, len) == 0) if (strncasecmp(_ctloc(abmon[i]), (const char*)bp, len) == 0)
break; break;
} }
/* Nothing matched. */ /* Nothing matched. */
if (i == 12) if (i == 12)
return (NULL); return (NULL);
tm->tm_mon = i; tm->tm_mon = i;
bp += len; bp += len;
break; break;
case 'C': /* The century number. */ case 'C': /* The century number. */
_LEGAL_ALT(_ALT_E); _LEGAL_ALT(_ALT_E);
if (!(_conv_num(&bp, &i, 0, 99))) if (!(_conv_num(&bp, &i, 0, 99)))
return (NULL); return (NULL);
century = i * 100; century = i * 100;
break; break;
case 'd': /* The day of month. */ case 'd': /* The day of month. */
case 'e': case 'e':
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
if (!(_conv_num(&bp, &tm->tm_mday, 1, 31))) if (!(_conv_num(&bp, &tm->tm_mday, 1, 31)))
return (NULL); return (NULL);
break; break;
case 'k': /* The hour (24-hour clock representation). */ case 'k': /* The hour (24-hour clock representation). */
_LEGAL_ALT(0); _LEGAL_ALT(0);
/* FALLTHROUGH */ /* FALLTHROUGH */
case 'H': case 'H':
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
if (!(_conv_num(&bp, &tm->tm_hour, 0, 23))) if (!(_conv_num(&bp, &tm->tm_hour, 0, 23)))
return (NULL); return (NULL);
break; break;
case 'l': /* The hour (12-hour clock representation). */ case 'l': /* The hour (12-hour clock representation). */
_LEGAL_ALT(0); _LEGAL_ALT(0);
/* FALLTHROUGH */ /* FALLTHROUGH */
case 'I': case 'I':
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
if (!(_conv_num(&bp, &tm->tm_hour, 1, 12))) if (!(_conv_num(&bp, &tm->tm_hour, 1, 12)))
return (NULL); return (NULL);
break; break;
case 'j': /* The day of year. */ case 'j': /* The day of year. */
_LEGAL_ALT(0); _LEGAL_ALT(0);
if (!(_conv_num(&bp, &tm->tm_yday, 1, 366))) if (!(_conv_num(&bp, &tm->tm_yday, 1, 366)))
return (NULL); return (NULL);
tm->tm_yday--; tm->tm_yday--;
break; break;
case 'M': /* The minute. */ case 'M': /* The minute. */
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
if (!(_conv_num(&bp, &tm->tm_min, 0, 59))) if (!(_conv_num(&bp, &tm->tm_min, 0, 59)))
return (NULL); return (NULL);
break; break;
case 'm': /* The month. */ case 'm': /* The month. */
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
if (!(_conv_num(&bp, &tm->tm_mon, 1, 12))) if (!(_conv_num(&bp, &tm->tm_mon, 1, 12)))
return (NULL); return (NULL);
tm->tm_mon--; tm->tm_mon--;
break; break;
case 'p': /* The locale's equivalent of AM/PM. */ case 'p': /* The locale's equivalent of AM/PM. */
_LEGAL_ALT(0); _LEGAL_ALT(0);
/* AM? */ /* AM? */
len = strlen(_ctloc(am_pm[0])); len = strlen(_ctloc(am_pm[0]));
if (strncasecmp(_ctloc(am_pm[0]), bp, len) == 0) { if (strncasecmp(_ctloc(am_pm[0]), (const char*)bp, len) == 0) {
if (tm->tm_hour > 12) /* i.e., 13:00 AM ?! */ if (tm->tm_hour > 12) /* i.e., 13:00 AM ?! */
return (NULL); return (NULL);
else if (tm->tm_hour == 12) else if (tm->tm_hour == 12)
tm->tm_hour = 0; tm->tm_hour = 0;
bp += len; bp += len;
break; break;
} }
/* PM? */ /* PM? */
len = strlen(_ctloc(am_pm[1])); len = strlen(_ctloc(am_pm[1]));
if (strncasecmp(_ctloc(am_pm[1]), bp, len) == 0) { if (strncasecmp(_ctloc(am_pm[1]), (const char*)bp, len) == 0) {
if (tm->tm_hour > 12) /* i.e., 13:00 PM ?! */ if (tm->tm_hour > 12) /* i.e., 13:00 PM ?! */
return (NULL); return (NULL);
else if (tm->tm_hour < 12) else if (tm->tm_hour < 12)
tm->tm_hour += 12; tm->tm_hour += 12;
bp += len; bp += len;
break; break;
} }
/* Nothing matched. */ /* Nothing matched. */
return (NULL); return (NULL);
case 'S': /* The seconds. */ case 'S': /* The seconds. */
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
if (!(_conv_num(&bp, &tm->tm_sec, 0, 61))) if (!(_conv_num(&bp, &tm->tm_sec, 0, 61)))
return (NULL); return (NULL);
break; break;
case 'U': /* The week of year, beginning on sunday. */ case 'U': /* The week of year, beginning on sunday. */
case 'W': /* The week of year, beginning on monday. */ case 'W': /* The week of year, beginning on monday. */
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
/* /*
* XXX This is bogus, as we can not assume any valid * XXX This is bogus, as we can not assume any valid
* information present in the tm structure at this * information present in the tm structure at this
* point to calculate a real value, so just check the * point to calculate a real value, so just check the
* range for now. * range for now.
*/ */
if (!(_conv_num(&bp, &i, 0, 53))) if (!(_conv_num(&bp, &i, 0, 53)))
return (NULL); return (NULL);
break; break;
case 'w': /* The day of week, beginning on sunday. */ case 'w': /* The day of week, beginning on sunday. */
_LEGAL_ALT(_ALT_O); _LEGAL_ALT(_ALT_O);
if (!(_conv_num(&bp, &tm->tm_wday, 0, 6))) if (!(_conv_num(&bp, &tm->tm_wday, 0, 6)))
return (NULL); return (NULL);
break; break;
case 'Y': /* The year. */ case 'Y': /* The year. */
_LEGAL_ALT(_ALT_E); _LEGAL_ALT(_ALT_E);
if (!(_conv_num(&bp, &i, 0, 9999))) if (!(_conv_num(&bp, &i, 0, 9999)))
return (NULL); return (NULL);
relyear = -1; relyear = -1;
tm->tm_year = i - TM_YEAR_BASE; tm->tm_year = i - TM_YEAR_BASE;
break; break;
case 'y': /* The year within the century (2 digits). */ case 'y': /* The year within the century (2 digits). */
_LEGAL_ALT(_ALT_E | _ALT_O); _LEGAL_ALT(_ALT_E | _ALT_O);
if (!(_conv_num(&bp, &relyear, 0, 99))) if (!(_conv_num(&bp, &relyear, 0, 99)))
return (NULL); return (NULL);
break; break;
/* /*
* Miscellaneous conversions. * Miscellaneous conversions.
*/ */
case 'n': /* Any kind of white-space. */ case 'n': /* Any kind of white-space. */
case 't': case 't':
_LEGAL_ALT(0); _LEGAL_ALT(0);
while (isspace(*bp)) while (isspace(*bp))
bp++; bp++;
break; break;
default: /* Unknown/unsupported conversion. */ default: /* Unknown/unsupported conversion. */
return (NULL); return (NULL);
} }
} }
/* /*
* We need to evaluate the two digit year spec (%y) * We need to evaluate the two digit year spec (%y)
* last as we can get a century spec (%C) at any time. * last as we can get a century spec (%C) at any time.
*/ */
if (relyear != -1) { if (relyear != -1) {
if (century == TM_YEAR_BASE) { if (century == TM_YEAR_BASE) {
if (relyear <= 68) if (relyear <= 68)
tm->tm_year = relyear + 2000 - TM_YEAR_BASE; tm->tm_year = relyear + 2000 - TM_YEAR_BASE;
else else
tm->tm_year = relyear + 1900 - TM_YEAR_BASE; tm->tm_year = relyear + 1900 - TM_YEAR_BASE;
} else { } else {
tm->tm_year = relyear + century - TM_YEAR_BASE; tm->tm_year = relyear + century - TM_YEAR_BASE;
} }
} }
return ((char *)bp); return (unsigned char*)bp;
} }
static int static int
_conv_num(const unsigned char **buf, int *dest, int llim, int ulim) _conv_num(const unsigned char **buf, int *dest, int llim, int ulim)
{ {
int result = 0; int result = 0;
int rulim = ulim; int rulim = ulim;
if (**buf < '0' || **buf > '9') if (**buf < '0' || **buf > '9')
return (0); return (0);
/* we use rulim to break out of the loop when we run out of digits */ /* we use rulim to break out of the loop when we run out of digits */
do { do {
result *= 10; result *= 10;
result += *(*buf)++ - '0'; result += *(*buf)++ - '0';
rulim /= 10; rulim /= 10;
} while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9'); } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
if (result < llim || result > ulim) if (result < llim || result > ulim)
return (0); return (0);
*dest = result; *dest = result;
return (1); return (1);
} }

View File

@ -21,7 +21,7 @@
#ifndef lint #ifndef lint
#ifndef NOID #ifndef NOID
static char tzfilehid[] = "@(#)tzfile.h 8.1"; static char tzfilehid[] = "@(#)tzfile.h 8.1";
#endif /* !defined NOID */ #endif /* !defined NOID */
#endif /* !defined lint */ #endif /* !defined lint */
@ -34,54 +34,54 @@ static char tzfilehid[] = "@(#)tzfile.h 8.1";
#endif /* !defined TZDIR */ #endif /* !defined TZDIR */
#ifndef TZDEFAULT #ifndef TZDEFAULT
#define TZDEFAULT "localtime" #define TZDEFAULT "localtime"
#endif /* !defined TZDEFAULT */ #endif /* !defined TZDEFAULT */
#ifndef TZDEFRULES #ifndef TZDEFRULES
#define TZDEFRULES "posixrules" #define TZDEFRULES "posixrules"
#endif /* !defined TZDEFRULES */ #endif /* !defined TZDEFRULES */
/* /*
** Each file begins with. . . ** Each file begins with. . .
*/ */
#define TZ_MAGIC "TZif" #define TZ_MAGIC "TZif"
struct tzhead { struct tzhead {
char tzh_magic[4]; /* TZ_MAGIC */ char tzh_magic[4]; /* TZ_MAGIC */
char tzh_version[1]; /* '\0' or '2' as of 2005 */ char tzh_version[1]; /* '\0' or '2' as of 2005 */
char tzh_reserved[15]; /* reserved--must be zero */ char tzh_reserved[15]; /* reserved--must be zero */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */ char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */ char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */ char tzh_typecnt[4]; /* coded number of local time types */
char tzh_charcnt[4]; /* coded number of abbr. chars */ char tzh_charcnt[4]; /* coded number of abbr. chars */
}; };
/* /*
** . . .followed by. . . ** . . .followed by. . .
** **
** tzh_timecnt (char [4])s coded transition times a la time(2) ** tzh_timecnt (char [4])s coded transition times a la time(2)
** tzh_timecnt (unsigned char)s types of local time starting at above ** tzh_timecnt (unsigned char)s types of local time starting at above
** tzh_typecnt repetitions of ** tzh_typecnt repetitions of
** one (char [4]) coded UTC offset in seconds ** one (char [4]) coded UTC offset in seconds
** one (unsigned char) used to set tm_isdst ** one (unsigned char) used to set tm_isdst
** one (unsigned char) that's an abbreviation list index ** one (unsigned char) that's an abbreviation list index
** tzh_charcnt (char)s '\0'-terminated zone abbreviations ** tzh_charcnt (char)s '\0'-terminated zone abbreviations
** tzh_leapcnt repetitions of ** tzh_leapcnt repetitions of
** one (char [4]) coded leap second transition times ** one (char [4]) coded leap second transition times
** one (char [4]) total correction after above ** one (char [4]) total correction after above
** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition ** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
** time is standard time, if FALSE, ** time is standard time, if FALSE,
** transition time is wall clock time ** transition time is wall clock time
** if absent, transition times are ** if absent, transition times are
** assumed to be wall clock time ** assumed to be wall clock time
** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition ** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
** time is UTC, if FALSE, ** time is UTC, if FALSE,
** transition time is local time ** transition time is local time
** if absent, transition times are ** if absent, transition times are
** assumed to be local time ** assumed to be local time
*/ */
/* /*
@ -100,81 +100,81 @@ struct tzhead {
*/ */
#ifndef TZ_MAX_TIMES #ifndef TZ_MAX_TIMES
#define TZ_MAX_TIMES 1200 #define TZ_MAX_TIMES 1200
#endif /* !defined TZ_MAX_TIMES */ #endif /* !defined TZ_MAX_TIMES */
#ifndef TZ_MAX_TYPES #ifndef TZ_MAX_TYPES
#ifndef NOSOLAR #ifndef NOSOLAR
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ #define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
#endif /* !defined NOSOLAR */ #endif /* !defined NOSOLAR */
#ifdef NOSOLAR #ifdef NOSOLAR
/* /*
** Must be at least 14 for Europe/Riga as of Jan 12 1995, ** Must be at least 14 for Europe/Riga as of Jan 12 1995,
** as noted by Earl Chew. ** as noted by Earl Chew.
*/ */
#define TZ_MAX_TYPES 20 /* Maximum number of local time types */ #define TZ_MAX_TYPES 20 /* Maximum number of local time types */
#endif /* !defined NOSOLAR */ #endif /* !defined NOSOLAR */
#endif /* !defined TZ_MAX_TYPES */ #endif /* !defined TZ_MAX_TYPES */
#ifndef TZ_MAX_CHARS #ifndef TZ_MAX_CHARS
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ #define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
/* (limited by what unsigned chars can hold) */ /* (limited by what unsigned chars can hold) */
#endif /* !defined TZ_MAX_CHARS */ #endif /* !defined TZ_MAX_CHARS */
#ifndef TZ_MAX_LEAPS #ifndef TZ_MAX_LEAPS
#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ #define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
#endif /* !defined TZ_MAX_LEAPS */ #endif /* !defined TZ_MAX_LEAPS */
#define SECSPERMIN 60 #define SECSPERMIN 60
#define MINSPERHOUR 60 #define MINSPERHOUR 60
#define HOURSPERDAY 24 #define HOURSPERDAY 24
#define DAYSPERWEEK 7 #define DAYSPERWEEK 7
#define DAYSPERNYEAR 365 #define DAYSPERNYEAR 365
#define DAYSPERLYEAR 366 #define DAYSPERLYEAR 366
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) #define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
#define MONSPERYEAR 12 #define MONSPERYEAR 12
#define TM_SUNDAY 0 #define TM_SUNDAY 0
#define TM_MONDAY 1 #define TM_MONDAY 1
#define TM_TUESDAY 2 #define TM_TUESDAY 2
#define TM_WEDNESDAY 3 #define TM_WEDNESDAY 3
#define TM_THURSDAY 4 #define TM_THURSDAY 4
#define TM_FRIDAY 5 #define TM_FRIDAY 5
#define TM_SATURDAY 6 #define TM_SATURDAY 6
#define TM_JANUARY 0 #define TM_JANUARY 0
#define TM_FEBRUARY 1 #define TM_FEBRUARY 1
#define TM_MARCH 2 #define TM_MARCH 2
#define TM_APRIL 3 #define TM_APRIL 3
#define TM_MAY 4 #define TM_MAY 4
#define TM_JUNE 5 #define TM_JUNE 5
#define TM_JULY 6 #define TM_JULY 6
#define TM_AUGUST 7 #define TM_AUGUST 7
#define TM_SEPTEMBER 8 #define TM_SEPTEMBER 8
#define TM_OCTOBER 9 #define TM_OCTOBER 9
#define TM_NOVEMBER 10 #define TM_NOVEMBER 10
#define TM_DECEMBER 11 #define TM_DECEMBER 11
#define TM_YEAR_BASE 1900 #define TM_YEAR_BASE 1900
#define EPOCH_YEAR 1970 #define EPOCH_YEAR 1970
#define EPOCH_WDAY TM_THURSDAY #define EPOCH_WDAY TM_THURSDAY
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
/* /*
** Since everything in isleap is modulo 400 (or a factor of 400), we know that ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
** isleap(y) == isleap(y % 400) ** isleap(y) == isleap(y % 400)
** and so ** and so
** isleap(a + b) == isleap((a + b) % 400) ** isleap(a + b) == isleap((a + b) % 400)
** or ** or
** isleap(a + b) == isleap(a % 400 + b % 400) ** isleap(a + b) == isleap(a % 400 + b % 400)
** This is true even if % means modulo rather than Fortran remainder ** This is true even if % means modulo rather than Fortran remainder
** (which is allowed by C89 but not C99). ** (which is allowed by C89 but not C99).
** We use this to avoid addition overflow problems. ** We use this to avoid addition overflow problems.
*/ */
#define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
#endif /* !defined TZFILE_H */ #endif /* !defined TZFILE_H */