diff options
Diffstat (limited to 'newlib/libc/time')
-rw-r--r-- | newlib/libc/time/Makefile.am | 13 | ||||
-rw-r--r-- | newlib/libc/time/Makefile.in | 81 | ||||
-rw-r--r-- | newlib/libc/time/asctime.c | 4 | ||||
-rw-r--r-- | newlib/libc/time/clock.c | 2 | ||||
-rw-r--r-- | newlib/libc/time/ctime.c | 9 | ||||
-rw-r--r-- | newlib/libc/time/difftime.c | 2 | ||||
-rw-r--r-- | newlib/libc/time/gettzinfo.c | 15 | ||||
-rw-r--r-- | newlib/libc/time/gmtime.c | 5 | ||||
-rw-r--r-- | newlib/libc/time/gmtime_r.c | 7 | ||||
-rw-r--r-- | newlib/libc/time/lcltime.c | 3 | ||||
-rw-r--r-- | newlib/libc/time/lcltime_r.c | 90 | ||||
-rw-r--r-- | newlib/libc/time/local.h | 36 | ||||
-rw-r--r-- | newlib/libc/time/mktime.c | 56 | ||||
-rw-r--r-- | newlib/libc/time/mktm_r.c | 257 | ||||
-rw-r--r-- | newlib/libc/time/strftime.c | 591 | ||||
-rw-r--r-- | newlib/libc/time/strptime.c | 446 | ||||
-rw-r--r-- | newlib/libc/time/time.tex | 24 | ||||
-rw-r--r-- | newlib/libc/time/tzlock.c | 56 | ||||
-rw-r--r-- | newlib/libc/time/tzset.c | 72 | ||||
-rw-r--r-- | newlib/libc/time/tzset_r.c | 199 | ||||
-rw-r--r-- | newlib/libc/time/tzvars.c | 10 |
21 files changed, 265 insertions, 1713 deletions
diff --git a/newlib/libc/time/Makefile.am b/newlib/libc/time/Makefile.am index f5c9a02a7..1ad24c0bf 100644 --- a/newlib/libc/time/Makefile.am +++ b/newlib/libc/time/Makefile.am @@ -11,20 +11,13 @@ LIB_SOURCES = \ ctime.c \ ctime_r.c \ difftime.c \ - gettzinfo.c \ gmtime.c \ gmtime_r.c \ lcltime.c \ lcltime_r.c \ mktime.c \ - mktm_r.c \ strftime.c \ - strptime.c \ - time.c \ - tzlock.c \ - tzset.c \ - tzset_r.c \ - tzvars.c + time.c libtime_la_LDFLAGS = -Xcompiler -nostdlib @@ -49,9 +42,7 @@ CHEWOUT_FILES = \ lcltime.def \ mktime.def \ strftime.def \ - time.def \ - tzlock.def \ - tzset.def + time.def SUFFIXES = .def diff --git a/newlib/libc/time/Makefile.in b/newlib/libc/time/Makefile.in index abdfc6530..5dfdccc2b 100644 --- a/newlib/libc/time/Makefile.in +++ b/newlib/libc/time/Makefile.in @@ -1,6 +1,6 @@ -# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am +# Makefile.in generated automatically by automake 1.4 from Makefile.am -# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -58,32 +58,20 @@ POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : -build_alias = @build_alias@ -build_triplet = @build@ host_alias = @host_alias@ host_triplet = @host@ -target_alias = @target_alias@ -target_triplet = @target@ AR = @AR@ AS = @AS@ CC = @CC@ CPP = @CPP@ CRT0 = @CRT0@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ DLLTOOL = @DLLTOOL@ EXEEXT = @EXEEXT@ -GCJ = @GCJ@ -GCJFLAGS = @GCJFLAGS@ LDFLAGS = @LDFLAGS@ -LIBC_EXTRA_DEF = @LIBC_EXTRA_DEF@ -LIBC_EXTRA_LIB = @LIBC_EXTRA_LIB@ LIBC_MACHINE_LIB = @LIBC_MACHINE_LIB@ LIBC_POSIX_LIB = @LIBC_POSIX_LIB@ LIBC_SIGNAL_DEF = @LIBC_SIGNAL_DEF@ LIBC_SIGNAL_LIB = @LIBC_SIGNAL_LIB@ -LIBC_STDIO64_DEF = @LIBC_STDIO64_DEF@ -LIBC_STDIO64_LIB = @LIBC_STDIO64_LIB@ LIBC_SYSCALL_LIB = @LIBC_SYSCALL_LIB@ LIBC_SYS_LIB = @LIBC_SYS_LIB@ LIBC_UNIX_LIB = @LIBC_UNIX_LIB@ @@ -93,13 +81,10 @@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ NEWLIB_CFLAGS = @NEWLIB_CFLAGS@ OBJDUMP = @OBJDUMP@ -OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ -STRIP = @STRIP@ VERSION = @VERSION@ aext = @aext@ -extra_dir = @extra_dir@ libm_machine_dir = @libm_machine_dir@ machine_dir = @machine_dir@ newlib_basedir = @newlib_basedir@ @@ -110,19 +95,41 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -LIB_SOURCES = asctime.c asctime_r.c clock.c ctime.c ctime_r.c difftime.c gettzinfo.c gmtime.c gmtime_r.c lcltime.c lcltime_r.c mktime.c mktm_r.c strftime.c strptime.c time.c tzlock.c tzset.c tzset_r.c tzvars.c +LIB_SOURCES = \ + asctime.c \ + asctime_r.c \ + clock.c \ + ctime.c \ + ctime_r.c \ + difftime.c \ + gmtime.c \ + gmtime_r.c \ + lcltime.c \ + lcltime_r.c \ + mktime.c \ + strftime.c \ + time.c libtime_la_LDFLAGS = -Xcompiler -nostdlib -@USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = libtime.la -@USE_LIBTOOL_TRUE@libtime_la_SOURCES = $(LIB_SOURCES) -@USE_LIBTOOL_TRUE@noinst_DATA = objectlist.awk.in +@USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = @USE_LIBTOOL_TRUE@libtime.la +@USE_LIBTOOL_TRUE@libtime_la_SOURCES = @USE_LIBTOOL_TRUE@$(LIB_SOURCES) +@USE_LIBTOOL_TRUE@noinst_DATA = @USE_LIBTOOL_TRUE@objectlist.awk.in @USE_LIBTOOL_FALSE@noinst_DATA = -@USE_LIBTOOL_FALSE@noinst_LIBRARIES = lib.a -@USE_LIBTOOL_FALSE@lib_a_SOURCES = $(LIB_SOURCES) +@USE_LIBTOOL_FALSE@noinst_LIBRARIES = @USE_LIBTOOL_FALSE@lib.a +@USE_LIBTOOL_FALSE@lib_a_SOURCES = @USE_LIBTOOL_FALSE@$(LIB_SOURCES) -CHEWOUT_FILES = asctime.def clock.def ctime.def difftime.def gmtime.def lcltime.def mktime.def strftime.def time.def tzlock.def tzset.def +CHEWOUT_FILES = \ + asctime.def \ + clock.def \ + ctime.def \ + difftime.def \ + gmtime.def \ + lcltime.def \ + mktime.def \ + strftime.def \ + time.def SUFFIXES = .def @@ -141,23 +148,15 @@ DEFS = @DEFS@ -I. -I$(srcdir) CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ lib_a_LIBADD = -@USE_LIBTOOL_FALSE@lib_a_OBJECTS = asctime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@asctime_r.$(OBJEXT) clock.$(OBJEXT) ctime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@ctime_r.$(OBJEXT) difftime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@gettzinfo.$(OBJEXT) gmtime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@gmtime_r.$(OBJEXT) lcltime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@lcltime_r.$(OBJEXT) mktime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@mktm_r.$(OBJEXT) strftime.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@strptime.$(OBJEXT) time.$(OBJEXT) tzlock.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@tzset.$(OBJEXT) tzset_r.$(OBJEXT) tzvars.$(OBJEXT) +@USE_LIBTOOL_FALSE@lib_a_OBJECTS = asctime.o asctime_r.o clock.o \ +@USE_LIBTOOL_FALSE@ctime.o ctime_r.o difftime.o gmtime.o gmtime_r.o \ +@USE_LIBTOOL_FALSE@lcltime.o lcltime_r.o mktime.o strftime.o time.o LTLIBRARIES = $(noinst_LTLIBRARIES) libtime_la_LIBADD = @USE_LIBTOOL_TRUE@libtime_la_OBJECTS = asctime.lo asctime_r.lo clock.lo \ -@USE_LIBTOOL_TRUE@ctime.lo ctime_r.lo difftime.lo gettzinfo.lo \ -@USE_LIBTOOL_TRUE@gmtime.lo gmtime_r.lo lcltime.lo lcltime_r.lo \ -@USE_LIBTOOL_TRUE@mktime.lo mktm_r.lo strftime.lo strptime.lo time.lo \ -@USE_LIBTOOL_TRUE@tzlock.lo tzset.lo tzset_r.lo tzvars.lo +@USE_LIBTOOL_TRUE@ctime.lo ctime_r.lo difftime.lo gmtime.lo gmtime_r.lo \ +@USE_LIBTOOL_TRUE@lcltime.lo lcltime_r.lo mktime.lo strftime.lo time.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -177,7 +176,7 @@ OBJECTS = $(lib_a_OBJECTS) $(libtime_la_OBJECTS) all: all-redirect .SUFFIXES: -.SUFFIXES: .S .c .def .lo .o .obj .s +.SUFFIXES: .S .c .def .lo .o .s $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) $(srcdir)/../../Makefile.shared cd $(top_srcdir) && $(AUTOMAKE) --cygnus time/Makefile @@ -198,11 +197,6 @@ maintainer-clean-noinstLIBRARIES: .c.o: $(COMPILE) -c $< -# FIXME: We should only use cygpath when building on Windows, -# and only if it is available. -.c.obj: - $(COMPILE) -c `cygpath -w $<` - .s.o: $(COMPILE) -c $< @@ -211,7 +205,6 @@ maintainer-clean-noinstLIBRARIES: mostlyclean-compile: -rm -f *.o core *.core - -rm -f *.$(OBJEXT) clean-compile: diff --git a/newlib/libc/time/asctime.c b/newlib/libc/time/asctime.c index e4011856d..4ad35e806 100644 --- a/newlib/libc/time/asctime.c +++ b/newlib/libc/time/asctime.c @@ -57,8 +57,8 @@ char * _DEFUN (asctime, (tim_p), _CONST struct tm *tim_p) { - _REENT_CHECK_ASCTIME_BUF(_REENT); - return asctime_r (tim_p, _REENT_ASCTIME_BUF(_REENT)); + char *buf = _REENT->_new._reent._asctime_buf; + return asctime_r (tim_p, buf); } #endif diff --git a/newlib/libc/time/clock.c b/newlib/libc/time/clock.c index 64cf438fb..b15915d6a 100644 --- a/newlib/libc/time/clock.c +++ b/newlib/libc/time/clock.c @@ -41,7 +41,7 @@ into seconds, divide by the macro <<CLOCKS_PER_SEC>>. RETURNS The amount of processor time used so far by your program, in units defined by the machine-dependent macro <<CLOCKS_PER_SEC>>. If no -measurement is available, the result is (clock_t)<<-1>>. +measurement is available, the result is <<-1>>. PORTABILITY ANSI C requires <<clock>> and <<CLOCKS_PER_SEC>>. diff --git a/newlib/libc/time/ctime.c b/newlib/libc/time/ctime.c index 63954c640..e8ccc144a 100644 --- a/newlib/libc/time/ctime.c +++ b/newlib/libc/time/ctime.c @@ -12,16 +12,15 @@ INDEX ANSI_SYNOPSIS #include <time.h> - char *ctime(const time_t *<[clock]>); - char *ctime_r(const time_t *<[clock]>, char *<[buf]>); + char *ctime(time_t <[clock]>); + char *ctime_r(time_t <[clock]>, char *<[buf]>); TRAD_SYNOPSIS #include <time.h> char *ctime(<[clock]>) - time_t *<[clock]>; - + time_t <[clock]>; char *ctime_r(<[clock]>, <[buf]>) - time_t *<[clock]>; + time_t <[clock]>; char *<[buf]>; DESCRIPTION diff --git a/newlib/libc/time/difftime.c b/newlib/libc/time/difftime.c index de6ffdb5c..93a4f0004 100644 --- a/newlib/libc/time/difftime.c +++ b/newlib/libc/time/difftime.c @@ -40,5 +40,5 @@ _DEFUN (difftime, (tim1, tim2), time_t tim1 _AND time_t tim2) { - return (double)(tim1 - tim2); + return ((double) tim1 - tim2); } diff --git a/newlib/libc/time/gettzinfo.c b/newlib/libc/time/gettzinfo.c deleted file mode 100644 index 54c9bc2f0..000000000 --- a/newlib/libc/time/gettzinfo.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <sys/types.h> -#include <local.h> - -/* Shared timezone information for libc/time functions. */ -static __tzinfo_type tzinfo = {1, 0, - { {'J', 0, 0, 0, 0, (time_t)0, 0L }, - {'J', 0, 0, 0, 0, (time_t)0, 0L } - } -}; - -__tzinfo_type * -__gettzinfo (void) -{ - return &tzinfo; -} diff --git a/newlib/libc/time/gmtime.c b/newlib/libc/time/gmtime.c index d8e687559..4f5bbe403 100644 --- a/newlib/libc/time/gmtime.c +++ b/newlib/libc/time/gmtime.c @@ -59,8 +59,9 @@ struct tm * _DEFUN (gmtime, (tim_p), _CONST time_t * tim_p) { - _REENT_CHECK_TM(_REENT); - return gmtime_r (tim_p, (struct tm *)_REENT_TM(_REENT)); + time_t tim = *tim_p + _GMT_OFFSET; + + return (localtime (&tim)); } #endif diff --git a/newlib/libc/time/gmtime_r.c b/newlib/libc/time/gmtime_r.c index fb39238d3..7afa021c5 100644 --- a/newlib/libc/time/gmtime_r.c +++ b/newlib/libc/time/gmtime_r.c @@ -3,12 +3,15 @@ */ #include <time.h> -#include "local.h" + +#define _GMT_OFFSET 0 struct tm * _DEFUN (gmtime_r, (tim_p, res), _CONST time_t * tim_p _AND struct tm *res) { - return (_mktm_r (tim_p, res, 1)); + time_t tim = *tim_p + _GMT_OFFSET; + + return (localtime_r (&tim, res)); } diff --git a/newlib/libc/time/lcltime.c b/newlib/libc/time/lcltime.c index 1cdc64fd0..e54a49d37 100644 --- a/newlib/libc/time/lcltime.c +++ b/newlib/libc/time/lcltime.c @@ -51,8 +51,7 @@ struct tm * _DEFUN (localtime, (tim_p), _CONST time_t * tim_p) { - _REENT_CHECK_TM(_REENT); - return localtime_r (tim_p, (struct tm *)_REENT_TM(_REENT)); + return localtime_r (tim_p, (struct tm *)&(_REENT->_new._reent._localtime_buf)); } #endif diff --git a/newlib/libc/time/lcltime_r.c b/newlib/libc/time/lcltime_r.c index cf386719c..1b4269ee1 100644 --- a/newlib/libc/time/lcltime_r.c +++ b/newlib/libc/time/lcltime_r.c @@ -1,18 +1,104 @@ /* * localtime_r.c + * Original Author: Adapted from tzcode maintained by Arthur David Olson. * * Converts the calendar time pointed to by tim_p into a broken-down time * expressed as local time. Returns a pointer to a structure containing the * broken-down time. */ +#include <stdlib.h> #include <time.h> -#include "local.h" + +#define SECSPERMIN 60L +#define MINSPERHOUR 60L +#define HOURSPERDAY 24L +#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) +#define SECSPERDAY (SECSPERHOUR * HOURSPERDAY) +#define DAYSPERWEEK 7 +#define MONSPERYEAR 12 + +#define YEAR_BASE 1900 +#define EPOCH_YEAR 1970 +#define EPOCH_WDAY 4 + +#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) + +static _CONST int mon_lengths[2][MONSPERYEAR] = { + {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, + {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} +} ; + +static _CONST int year_lengths[2] = { + 365, + 366 +} ; struct tm * _DEFUN (localtime_r, (tim_p, res), _CONST time_t * tim_p _AND struct tm *res) { - return _mktm_r (tim_p, res, 0); + long days, rem; + int y; + int yleap; + _CONST int *ip; + + days = ((long) *tim_p) / SECSPERDAY; + rem = ((long) *tim_p) % SECSPERDAY; + while (rem < 0) + { + rem += SECSPERDAY; + --days; + } + while (rem >= SECSPERDAY) + { + rem -= SECSPERDAY; + ++days; + } + + /* compute hour, min, and sec */ + res->tm_hour = (int) (rem / SECSPERHOUR); + rem %= SECSPERHOUR; + res->tm_min = (int) (rem / SECSPERMIN); + res->tm_sec = (int) (rem % SECSPERMIN); + + /* compute day of week */ + if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0) + res->tm_wday += DAYSPERWEEK; + + /* compute year & day of year */ + y = EPOCH_YEAR; + if (days >= 0) + { + for (;;) + { + yleap = isleap(y); + if (days < year_lengths[yleap]) + break; + y++; + days -= year_lengths[yleap]; + } + } + else + { + do + { + --y; + yleap = isleap(y); + days += year_lengths[yleap]; + } while (days < 0); + } + + res->tm_year = y - YEAR_BASE; + res->tm_yday = days; + ip = mon_lengths[yleap]; + for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon) + days -= ip[res->tm_mon]; + res->tm_mday = days + 1; + + /* set daylight saving time flag */ + res->tm_isdst = -1; + + return (res); } diff --git a/newlib/libc/time/local.h b/newlib/libc/time/local.h deleted file mode 100644 index 9d9ef87fa..000000000 --- a/newlib/libc/time/local.h +++ /dev/null @@ -1,36 +0,0 @@ -/* local header used by libc/time routines */ -#include <_ansi.h> -#include <time.h> - -#define SECSPERMIN 60L -#define MINSPERHOUR 60L -#define HOURSPERDAY 24L -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) -#define SECSPERDAY (SECSPERHOUR * HOURSPERDAY) -#define DAYSPERWEEK 7 -#define MONSPERYEAR 12 - -#define YEAR_BASE 1900 -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY 4 -#define EPOCH_YEARS_SINCE_LEAP 2 -#define EPOCH_YEARS_SINCE_CENTURY 70 -#define EPOCH_YEARS_SINCE_LEAP_CENTURY 370 - -#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) - -struct tm * _EXFUN (_mktm_r, (_CONST time_t *, struct tm *, int __is_gmtime)); -int _EXFUN (__tzcalc_limits, (int __year)); - -/* locks for multi-threading */ -#ifdef __SINGLE_THREAD__ -#define TZ_LOCK -#define TZ_UNLOCK -#else -#define TZ_LOCK __tz_lock() -#define TZ_UNLOCK __tz_unlock() -#endif - -void _EXFUN(__tz_lock,(_VOID)); -void _EXFUN(__tz_unlock,(_VOID)); - diff --git a/newlib/libc/time/mktime.c b/newlib/libc/time/mktime.c index 0ee055cd0..80478dae9 100644 --- a/newlib/libc/time/mktime.c +++ b/newlib/libc/time/mktime.c @@ -47,7 +47,6 @@ ANSI C requires <<mktime>>. #include <stdlib.h> #include <time.h> -#include "local.h" #define _SEC_IN_MINUTE 60L #define _SEC_IN_HOUR 3600L @@ -157,8 +156,7 @@ mktime (tim_p) { time_t tim = 0; long days = 0; - int year, isdst; - __tzinfo_type *tz = __gettzinfo (); + int year; /* validate structure */ validate_structure (tim_p); @@ -202,57 +200,5 @@ mktime (tim_p) /* compute total seconds */ tim += (days * _SEC_IN_DAY); - isdst = tim_p->tm_isdst; - - if (_daylight) - { - int y = tim_p->tm_year + YEAR_BASE; - if (y == tz->__tzyear || __tzcalc_limits (y)) - { - /* calculate start of dst in dst local time and - start of std in both std local time and dst local time */ - time_t startdst_dst = tz->__tzrule[0].change - - (time_t) tz->__tzrule[1].offset; - time_t startstd_dst = tz->__tzrule[1].change - - (time_t) tz->__tzrule[1].offset; - time_t startstd_std = tz->__tzrule[1].change - - (time_t) tz->__tzrule[0].offset; - /* if the time is in the overlap between dst and std local times */ - if (tim >= startstd_std && tim < startstd_dst) - ; /* we let user decide or leave as -1 */ - else - { - isdst = (tz->__tznorth - ? (tim >= startdst_dst && tim < startstd_std) - : (tim >= startdst_dst || tim < startstd_std)); - /* if user committed and was wrong, perform correction */ - if ((isdst ^ tim_p->tm_isdst) == 1) - { - /* we either subtract or add the difference between - time zone offsets, depending on which way the user got it - wrong. The diff is typically one hour, or 3600 seconds, - and should fit in a 16-bit int, even though offset - is a long to accomodate 12 hours. */ - int diff = (int) (tz->__tzrule[0].offset - - tz->__tzrule[1].offset); - if (!isdst) - diff = -diff; - tim_p->tm_sec += diff; - validate_structure (tim_p); - tim += diff; /* we also need to correct our current time calculation */ - } - } - } - } - - /* add appropriate offset to put time in gmt format */ - if (isdst == 1) - tim += (time_t) tz->__tzrule[1].offset; - else /* otherwise assume std time */ - tim += (time_t) tz->__tzrule[0].offset; - - /* reset isdst flag to what we have calculated */ - tim_p->tm_isdst = isdst; - return tim; } diff --git a/newlib/libc/time/mktm_r.c b/newlib/libc/time/mktm_r.c deleted file mode 100644 index 4d4b4fab0..000000000 --- a/newlib/libc/time/mktm_r.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * mktm_r.c - * Original Author: Adapted from tzcode maintained by Arthur David Olson. - * Modifications: Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston - * Fixed bug in mday computations - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru> - * Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov <alx@intellectronika.ru> - * - * Converts the calendar time pointed to by tim_p into a broken-down time - * expressed as local time. Returns a pointer to a structure containing the - * broken-down time. - */ - -#include <stdlib.h> -#include <time.h> -#include "local.h" - -static _CONST int mon_lengths[2][MONSPERYEAR] = { - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -} ; - -static _CONST int year_lengths[2] = { - 365, - 366 -} ; - -struct tm * -_DEFUN (_mktm_r, (tim_p, res, is_gmtime), - _CONST time_t * tim_p _AND - struct tm *res _AND - int is_gmtime) -{ - long days, rem; - time_t lcltime; - int y; - int yleap; - _CONST int *ip; - __tzinfo_type *tz = __gettzinfo (); - - /* base decision about std/dst time on current time */ - lcltime = *tim_p; - - days = ((long)lcltime) / SECSPERDAY; - rem = ((long)lcltime) % SECSPERDAY; - while (rem < 0) - { - rem += SECSPERDAY; - --days; - } - while (rem >= SECSPERDAY) - { - rem -= SECSPERDAY; - ++days; - } - - /* compute hour, min, and sec */ - res->tm_hour = (int) (rem / SECSPERHOUR); - rem %= SECSPERHOUR; - res->tm_min = (int) (rem / SECSPERMIN); - res->tm_sec = (int) (rem % SECSPERMIN); - - /* compute day of week */ - if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0) - res->tm_wday += DAYSPERWEEK; - - /* compute year & day of year */ - y = EPOCH_YEAR; - if (days >= 0) - { - for (;;) - { - yleap = isleap(y); - if (days < year_lengths[yleap]) - break; - y++; - days -= year_lengths[yleap]; - } - } - else - { - do - { - --y; - yleap = isleap(y); - days += year_lengths[yleap]; - } while (days < 0); - } - - res->tm_year = y - YEAR_BASE; - res->tm_yday = days; - ip = mon_lengths[yleap]; - for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon) - days -= ip[res->tm_mon]; - res->tm_mday = days + 1; - - if (!is_gmtime) - { - long offset; - int hours, mins, secs; - - TZ_LOCK; - if (_daylight) - { - if (y == tz->__tzyear || __tzcalc_limits (y)) - res->tm_isdst = (tz->__tznorth - ? (*tim_p >= tz->__tzrule[0].change - && *tim_p < tz->__tzrule[1].change) - : (*tim_p >= tz->__tzrule[0].change - || *tim_p < tz->__tzrule[1].change)); - else - res->tm_isdst = -1; - } - else - res->tm_isdst = 0; - - offset = (res->tm_isdst == 1 - ? tz->__tzrule[1].offset - : tz->__tzrule[0].offset); - - hours = (int) (offset / SECSPERHOUR); - offset = offset % SECSPERHOUR; - - mins = (int) (offset / SECSPERMIN); - secs = (int) (offset % SECSPERMIN); - - res->tm_sec -= secs; - res->tm_min -= mins; - res->tm_hour -= hours; - - if (res->tm_sec >= SECSPERMIN) - { - res->tm_min += 1; - res->tm_sec -= SECSPERMIN; - } - else if (res->tm_sec < 0) - { - res->tm_min -= 1; - res->tm_sec += SECSPERMIN; - } - if (res->tm_min >= MINSPERHOUR) - { - res->tm_hour += 1; - res->tm_min -= MINSPERHOUR; - } - else if (res->tm_min < 0) - { - res->tm_hour -= 1; - res->tm_min += MINSPERHOUR; - } - if (res->tm_hour >= HOURSPERDAY) - { - ++res->tm_yday; - ++res->tm_wday; - if (res->tm_wday > 6) - res->tm_wday = 0; - ++res->tm_mday; - res->tm_hour -= HOURSPERDAY; - if (res->tm_mday > ip[res->tm_mon]) - { - res->tm_mday -= ip[res->tm_mon]; - res->tm_mon += 1; - if (res->tm_mon == 12) - { - res->tm_mon = 0; - res->tm_year += 1; - res->tm_yday = 0; - } - } - } - else if (res->tm_hour < 0) - { - res->tm_yday -= 1; - res->tm_wday -= 1; - if (res->tm_wday < 0) - res->tm_wday = 6; - res->tm_mday -= 1; - res->tm_hour += 24; - if (res->tm_mday == 0) - { - res->tm_mon -= 1; - if (res->tm_mon < 0) - { - res->tm_mon = 11; - res->tm_year -= 1; - res->tm_yday = 365 + isleap(res->tm_year); - } - res->tm_mday = ip[res->tm_mon]; - } - } - TZ_UNLOCK; - } - else - res->tm_isdst = 0; - - return (res); -} - -int -_DEFUN (__tzcalc_limits, (year), - int year) -{ - int days, year_days, years; - int i, j; - __tzinfo_type *tz = __gettzinfo (); - - if (year < EPOCH_YEAR) - return 0; - - tz->__tzyear = year; - - years = (year - EPOCH_YEAR); - - year_days = years * 365 + - (years - 1 + EPOCH_YEARS_SINCE_LEAP) / 4 - (years - 1 + EPOCH_YEARS_SINCE_CENTURY) / 100 + - (years - 1 + EPOCH_YEARS_SINCE_LEAP_CENTURY) / 400; - - for (i = 0; i < 2; ++i) - { - if (tz->__tzrule[i].ch == 'J') - days = year_days + tz->__tzrule[i].d + - (isleap(year) && tz->__tzrule[i].d >= 60); - else if (tz->__tzrule[i].ch == 'D') - days = year_days + tz->__tzrule[i].d; - else - { - int yleap = isleap(year); - int m_day, m_wday, wday_diff; - _CONST int *ip = mon_lengths[yleap]; - - days = year_days; - - for (j = 1; j < tz->__tzrule[i].m; ++j) - days += ip[j-1]; - - m_wday = (EPOCH_WDAY + days) % DAYSPERWEEK; - - wday_diff = tz->__tzrule[i].d - m_wday; - if (wday_diff < 0) - wday_diff += DAYSPERWEEK; - m_day = (tz->__tzrule[i].n - 1) * DAYSPERWEEK + wday_diff; - - while (m_day >= ip[j-1]) - m_day -= DAYSPERWEEK; - - days += m_day; - } - - /* store the change-over time in GMT form by adding offset */ - tz->__tzrule[i].change = days * SECSPERDAY + - tz->__tzrule[i].s + tz->__tzrule[i].offset; - } - - tz->__tznorth = (tz->__tzrule[0].change < tz->__tzrule[1].change); - - return 1; -} - diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c index a3fdb745a..1b44e1db9 100644 --- a/newlib/libc/time/strftime.c +++ b/newlib/libc/time/strftime.c @@ -1,7 +1,6 @@ /* * strftime.c * Original Author: G. Haley - * Additions from: Eric Blake * * Places characters into the array pointed to by s as controlled by the string * pointed to by format. If the total number of resulting characters including @@ -33,195 +32,92 @@ TRAD_SYNOPSIS DESCRIPTION <<strftime>> converts a <<struct tm>> representation of the time (at -<[timp]>) into a null-terminated string, starting at <[s]> and occupying -no more than <[maxsize]> characters. +<[timp]>) into a string, starting at <[s]> and occupying no more than +<[maxsize]> characters. You control the format of the output using the string at <[format]>. <<*<[format]>>> can contain two kinds of specifications: text to be copied literally into the formatted string, and time conversion -specifications. Time conversion specifications are two- and -three-character sequences beginning with `<<%>>' (use `<<%%>>' to -include a percent sign in the output). Each defined conversion -specification selects only the specified field(s) of calendar time -data from <<*<[timp]>>>, and converts it to a string in one of the -following ways: +specifications. Time conversion specifications are two-character +sequences beginning with `<<%>>' (use `<<%%>>' to include a percent +sign in the output). Each defined conversion specification selects a +field of calendar time data from <<*<[timp]>>>, and converts it to a +string in one of the following ways: o+ o %a -A three-letter abbreviation for the day of the week. [tm_wday] +An abbreviation for the day of the week. o %A -The full name for the day of the week, one of `<<Sunday>>', -`<<Monday>>', `<<Tuesday>>', `<<Wednesday>>', `<<Thursday>>', -`<<Friday>>', or `<<Saturday>>'. [tm_wday] +The full name for the day of the week. o %b -A three-letter abbreviation for the month name. [tm_mon] +An abbreviation for the month name. o %B -The full name of the month, one of `<<January>>', `<<February>>', -`<<March>>', `<<April>>', `<<May>>', `<<June>>', `<<July>>', -`<<August>>', `<<September>>', `<<October>>', `<<November>>', -`<<December>>'. [tm_mon] +The full name of the month. o %c A string representing the complete date and time, in the form -`<<"%a %b %e %H:%M:%S %Y">>' (example "Mon Apr 01 13:13:13 -1992"). [tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday] - -o %C -The century, that is, the year divided by 100 then truncated. For -4-digit years, the result is zero-padded and exactly two characters; -but for other years, there may a negative sign or more digits. In -this way, `<<%C%y>>' is equivalent to `<<%Y>>'. [tm_year] - +. Mon Apr 01 13:13:13 1992 + o %d -The day of the month, formatted with two digits (from `<<01>>' to -`<<31>>'). [tm_mday] - -o %D -A string representing the date, in the form `<<"%m/%d/%y">>'. -[tm_mday, tm_mon, tm_year] - -o %e -The day of the month, formatted with leading space if single digit -(from `<<1>>' to `<<31>>'). [tm_mday] - -o %E<<x>> -In some locales, the E modifier selects alternative representations of -certain modifiers <<x>>. But in the "C" locale supported by newlib, -it is ignored, and treated as %<<x>>. - -o %F -A string representing the ISO 8601:2000 date format, in the form -`<<"%Y-%m-%d">>'. [tm_mday, tm_mon, tm_year] - -o %g -The last two digits of the week-based year, see specifier %G (from -`<<00>>' to `<<99>>'). [tm_year, tm_wday, tm_yday] - -o %G -The week-based year. In the ISO 8601:2000 calendar, week 1 of the year -includes January 4th, and begin on Mondays. Therefore, if January 1st, -2nd, or 3rd falls on a Sunday, that day and earlier belong to the last -week of the previous year; and if December 29th, 30th, or 31st falls -on Monday, that day and later belong to week 1 of the next year. For -consistency with %Y, it always has at least four characters. -Example: "%G" for Saturday 2nd January 1999 gives "1998", and for -Tuesday 30th December 1997 gives "1998". [tm_year, tm_wday, tm_yday] - -o %h -A three-letter abbreviation for the month name (synonym for -"%b"). [tm_mon] +The day of the month, formatted with two digits. o %H -The hour (on a 24-hour clock), formatted with two digits (from -`<<00>>' to `<<23>>'). [tm_hour] +The hour (on a 24-hour clock), formatted with two digits. o %I -The hour (on a 12-hour clock), formatted with two digits (from -`<<01>>' to `<<12>>'). [tm_hour] +The hour (on a 12-hour clock), formatted with two digits. o %j The count of days in the year, formatted with three digits -(from `<<001>>' to `<<366>>'). [tm_yday] - -o %k -The hour (on a 24-hour clock), formatted with leading space if single -digit (from `<<0>>' to `<<23>>'). Non-POSIX extension. [tm_hour] - -o %l -The hour (on a 12-hour clock), formatted with leading space if single -digit (from `<<1>>' to `<<12>>'). Non-POSIX extension. [tm_hour] +(from `<<001>>' to `<<366>>'). o %m -The month number, formatted with two digits (from `<<01>>' to `<<12>>'). -[tm_mon] +The month number, formatted with two digits. o %M -The minute, formatted with two digits (from `<<00>>' to `<<59>>'). [tm_min] - -o %n -A newline character (`<<\n>>'). - -o %O<<x>> -In some locales, the O modifier selects alternative digit characters -for certain modifiers <<x>>. But in the "C" locale supported by newlib, it -is ignored, and treated as %<<x>>. +The minute, formatted with two digits. o %p -Either `<<AM>>' or `<<PM>>' as appropriate. [tm_hour] - -o %r -The 12-hour time, to the second. Equivalent to "%I:%M:%S %p". [tm_sec, -tm_min, tm_hour] - -o %R -The 24-hour time, to the minute. Equivalent to "%H:%M". [tm_min, tm_hour] +Either `<<AM>>' or `<<PM>>' as appropriate. o %S -The second, formatted with two digits (from `<<00>>' to `<<60>>'). The -value 60 accounts for the occasional leap second. [tm_sec] - -o %t -A tab character (`<<\t>>'). - -o %T -The 24-hour time, to the second. Equivalent to "%H:%M:%S". [tm_sec, -tm_min, tm_hour] - -o %u -The weekday as a number, 1-based from Monday (from `<<1>>' to -`<<7>>'). [tm_wday] +The second, formatted with two digits. o %U -The week number, where weeks start on Sunday, week 1 contains the first -Sunday in a year, and earlier days are in week 0. Formatted with two -digits (from `<<00>>' to `<<53>>'). See also <<%W>>. [tm_wday, tm_yday] - -o %V -The week number, where weeks start on Monday, week 1 contains January 4th, -and earlier days are in the previous year. Formatted with two digits -(from `<<01>>' to `<<53>>'). See also <<%G>>. [tm_year, tm_wday, tm_yday] +The week number, formatted with two digits (from `<<00>>' to `<<53>>'; +week number 1 is taken as beginning with the first Sunday in a year). +See also <<%W>>. o %w -The weekday as a number, 0-based from Sunday (from `<<0>>' to `<<6>>'). -[tm_wday] +A single digit representing the day of the week: Sunday is day <<0>>. o %W -The week number, where weeks start on Monday, week 1 contains the first -Monday in a year, and earlier days are in week 0. Formatted with two -digits (from `<<00>>' to `<<53>>'). [tm_wday, tm_yday] +Another version of the week number: like `<<%U>>', but counting week 1 +as beginning with the first Monday in a year. +o o %x -A string representing the complete date, equivalent to "%m/%d/%y". -[tm_mon, tm_mday, tm_year] +A string representing the complete date, in a format like +. Mon Apr 01 1992 o %X A string representing the full time of day (hours, minutes, and -seconds), equivalent to "%H:%M:%S". [tm_sec, tm_min, tm_hour] +seconds), in a format like +. 13:13:13 o %y -The last two digits of the year (from `<<00>>' to `<<99>>'). [tm_year] +The last two digits of the year. o %Y -The full year, equivalent to <<%C%y>>. It will always have at least four -characters, but may have more. The year is accurate even when tm_year -added to the offset of 1900 overflows an int. [tm_year] - -o %z -The offset from UTC. The format consists of a sign (negative is west of -Greewich), two characters for hour, then two characters for minutes -(-hhmm or +hhmm). If tm_isdst is negative, the offset is unknown and no -output is generated; if it is zero, the offset is the standard offset for -the current time zone; and if it is positive, the offset is the daylight -savings offset for the current timezone. The offset is determined from -the TZ environment variable, as if by calling tzset(). [tm_isdst] +The full year, formatted with four digits to include the century. o %Z -The time zone name. If tm_isdst is negative, no output is generated. -Otherwise, the time zone name is based on the TZ environment variable, -as if by calling tzset(). [tm_isdst] +Defined by ANSI C as eliciting the time zone if available; it is not +available in this implementation (which accepts `<<%Z>>' but generates +no output for it). o %% A single character, `<<%>>'. @@ -238,12 +134,7 @@ parts of <<*<[format]>>> that could be completely filled in within the PORTABILITY ANSI C requires <<strftime>>, but does not specify the contents of <<*<[s]>>> when the formatted string would require more than -<[maxsize]> characters. Unrecognized specifiers and fields of -<<timp>> that are out of range cause undefined results. Since some -formats expand to 0 bytes, it is wise to set <<*<[s]>>> to a nonzero -value beforehand to distinguish between failure and an empty string. -This implementation does not support <<s>> being NULL, nor overlapping -<<s>> and <<format>>. +<[maxsize]> characters. <<strftime>> requires no supporting OS subroutines. */ @@ -251,9 +142,6 @@ This implementation does not support <<s>> being NULL, nor overlapping #include <stddef.h> #include <stdio.h> #include <time.h> -#include <string.h> -#include <stdlib.h> -#include "local.h" static _CONST int dname_len[7] = {6, 6, 7, 9, 8, 6, 8}; @@ -270,53 +158,6 @@ static _CONST char *_CONST mname[12] = "May", "June", "July", "August", "September", "October", "November", "December"}; -/* Using the tm_year, tm_wday, and tm_yday components of TIM_P, return - -1, 0, or 1 as the adjustment to add to the year for the ISO week - numbering used in "%g%G%V", avoiding overflow. */ -static int -_DEFUN (iso_year_adjust, (tim_p), - _CONST struct tm *tim_p) -{ - /* Account for fact that tm_year==0 is year 1900. */ - int leap = isleap (tim_p->tm_year + (YEAR_BASE - - (tim_p->tm_year < 0 ? 0 : 2000))); - - /* Pack the yday, wday, and leap year into a single int since there are so - many disparate cases. */ -#define PACK(yd, wd, lp) (((yd) << 4) + (wd << 1) + (lp)) - switch (PACK (tim_p->tm_yday, tim_p->tm_wday, leap)) - { - case PACK (0, 5, 0): /* Jan 1 is Fri, not leap. */ - case PACK (0, 6, 0): /* Jan 1 is Sat, not leap. */ - case PACK (0, 0, 0): /* Jan 1 is Sun, not leap. */ - case PACK (0, 5, 1): /* Jan 1 is Fri, leap year. */ - case PACK (0, 6, 1): /* Jan 1 is Sat, leap year. */ - case PACK (0, 0, 1): /* Jan 1 is Sun, leap year. */ - case PACK (1, 6, 0): /* Jan 2 is Sat, not leap. */ - case PACK (1, 0, 0): /* Jan 2 is Sun, not leap. */ - case PACK (1, 6, 1): /* Jan 2 is Sat, leap year. */ - case PACK (1, 0, 1): /* Jan 2 is Sun, leap year. */ - case PACK (2, 0, 0): /* Jan 3 is Sun, not leap. */ - case PACK (2, 0, 1): /* Jan 3 is Sun, leap year. */ - return -1; /* Belongs to last week of previous year. */ - case PACK (362, 1, 0): /* Dec 29 is Mon, not leap. */ - case PACK (363, 1, 1): /* Dec 29 is Mon, leap year. */ - case PACK (363, 1, 0): /* Dec 30 is Mon, not leap. */ - case PACK (363, 2, 0): /* Dec 30 is Tue, not leap. */ - case PACK (364, 1, 1): /* Dec 30 is Mon, leap year. */ - case PACK (364, 2, 1): /* Dec 30 is Tue, leap year. */ - case PACK (364, 1, 0): /* Dec 31 is Mon, not leap. */ - case PACK (364, 2, 0): /* Dec 31 is Tue, not leap. */ - case PACK (364, 3, 0): /* Dec 31 is Wed, not leap. */ - case PACK (365, 1, 1): /* Dec 31 is Mon, leap year. */ - case PACK (365, 2, 1): /* Dec 31 is Tue, leap year. */ - case PACK (365, 3, 1): /* Dec 31 is Wed, leap year. */ - return 1; /* Belongs to first week of next year. */ - } - return 0; /* Belongs to specified year. */ -#undef PACK -} - size_t _DEFUN (strftime, (s, maxsize, format, tim_p), char *s _AND @@ -341,9 +182,6 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), break; format++; - if (*format == 'E' || *format == 'O') - format++; - switch (*format) { case 'a': @@ -367,7 +205,6 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), } break; case 'b': - case 'h': for (i = 0; i < 3; i++) { if (count < maxsize - 1) @@ -388,141 +225,41 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), } break; case 'c': - { - /* Length is not known because of %C%y, so recurse. */ - size_t adjust = strftime (&s[count], maxsize - count, - "%a %b %e %H:%M:%S %C%y", tim_p); - if (adjust > 0) - count += adjust; - else - return 0; - } - break; - case 'C': - { - /* Examples of (tm_year + YEAR_BASE) that show how %Y == %C%y - with 32-bit int. - %Y %C %y - 2147485547 21474855 47 - 10000 100 00 - 9999 99 99 - 0999 09 99 - 0099 00 99 - 0001 00 01 - 0000 00 00 - -001 -0 01 - -099 -0 99 - -999 -9 99 - -1000 -10 00 - -10000 -100 00 - -2147481748 -21474817 48 - - Be careful of both overflow and sign adjustment due to the - asymmetric range of years. - */ - int neg = tim_p->tm_year < -YEAR_BASE; - int century = tim_p->tm_year >= 0 - ? tim_p->tm_year / 100 + YEAR_BASE / 100 - : abs (tim_p->tm_year + YEAR_BASE) / 100; - count += snprintf (&s[count], maxsize - count, "%s%.*d", - neg ? "-" : "", 2 - neg, century); - if (count >= maxsize) - return 0; - } - break; - case 'd': - case 'e': - if (count < maxsize - 2) - { - sprintf (&s[count], *format == 'd' ? "%.2d" : "%2d", - tim_p->tm_mday); - count += 2; - } - else - return 0; - break; - case 'D': - case 'x': - /* %m/%d/%y */ - if (count < maxsize - 8) + if (count < maxsize - 24) { - sprintf (&s[count], "%.2d/%.2d/%.2d", - tim_p->tm_mon + 1, tim_p->tm_mday, - tim_p->tm_year >= 0 ? tim_p->tm_year % 100 - : abs (tim_p->tm_year + YEAR_BASE) % 100); - count += 8; + for (i = 0; i < 3; i++) + s[count++] = + dname[tim_p->tm_wday][i]; + s[count++] = ' '; + for (i = 0; i < 3; i++) + s[count++] = + mname[tim_p->tm_mon][i]; + + sprintf (&s[count], + " %.2d %2.2d:%2.2d:%2.2d %.4d", + tim_p->tm_mday, tim_p->tm_hour, + tim_p->tm_min, + tim_p->tm_sec, 1900 + + tim_p->tm_year); + count += 17; } else return 0; break; - case 'F': - { - /* Length is not known because of %C%y, so recurse. */ - size_t adjust = strftime (&s[count], maxsize - count, - "%C%y-%m-%d", tim_p); - if (adjust > 0) - count += adjust; - else - return 0; - } - break; - case 'g': + case 'd': if (count < maxsize - 2) { - /* Be careful of both overflow and negative years, thanks to - the asymmetric range of years. */ - int adjust = iso_year_adjust (tim_p); - int year = tim_p->tm_year >= 0 ? tim_p->tm_year % 100 - : abs (tim_p->tm_year + YEAR_BASE) % 100; - if (adjust < 0 && tim_p->tm_year <= -YEAR_BASE) - adjust = 1; - else if (adjust > 0 && tim_p->tm_year < -YEAR_BASE) - adjust = -1; sprintf (&s[count], "%.2d", - ((year + adjust) % 100 + 100) % 100); + tim_p->tm_mday); count += 2; } else return 0; - break; - case 'G': - { - /* See the comments for 'C' and 'Y'; this is a variable length - field. Although there is no requirement for a minimum number - of digits, we use 4 for consistency with 'Y'. */ - int neg = tim_p->tm_year < -YEAR_BASE; - int adjust = iso_year_adjust (tim_p); - int century = tim_p->tm_year >= 0 - ? tim_p->tm_year / 100 + YEAR_BASE / 100 - : abs (tim_p->tm_year + YEAR_BASE) / 100; - int year = tim_p->tm_year >= 0 ? tim_p->tm_year % 100 - : abs (tim_p->tm_year + YEAR_BASE) % 100; - if (adjust < 0 && tim_p->tm_year <= -YEAR_BASE) - neg = adjust = 1; - else if (adjust > 0 && neg) - adjust = -1; - year += adjust; - if (year == -1) - { - year = 99; - --century; - } - else if (year == 100) - { - year = 0; - ++century; - } - count += snprintf (&s[count], maxsize - count, "%s%.*d%.2d", - neg ? "-" : "", 2 - neg, century, year); - if (count >= maxsize) - return 0; - } - break; + break; case 'H': - case 'k': if (count < maxsize - 2) { - sprintf (&s[count], *format == 'k' ? "%2d" : "%.2d", + sprintf (&s[count], "%2.2d", tim_p->tm_hour); count += 2; } @@ -530,7 +267,6 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), return 0; break; case 'I': - case 'l': if (count < maxsize - 2) { if (tim_p->tm_hour == 0 || @@ -541,7 +277,7 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), } else { - sprintf (&s[count], *format == 'I' ? "%.2d" : "%2d", + sprintf (&s[count], "%.2d", tim_p->tm_hour % 12); count += 2; } @@ -572,19 +308,13 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), case 'M': if (count < maxsize - 2) { - sprintf (&s[count], "%.2d", + sprintf (&s[count], "%2.2d", tim_p->tm_min); count += 2; } else return 0; break; - case 'n': - if (count < maxsize - 1) - s[count++] = '\n'; - else - return 0; - break; case 'p': if (count < maxsize - 2) { @@ -598,133 +328,76 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), else return 0; break; - case 'r': - if (count < maxsize - 11) + case 'S': + if (count < maxsize - 2) { - if (tim_p->tm_hour == 0 || - tim_p->tm_hour == 12) - { - s[count++] = '1'; - s[count++] = '2'; - } - else - { - sprintf (&s[count], "%.2d", tim_p->tm_hour % 12); - count += 2; - } - s[count++] = ':'; - sprintf (&s[count], "%.2d", - tim_p->tm_min); - count += 2; - s[count++] = ':'; - sprintf (&s[count], "%.2d", + sprintf (&s[count], "%2.2d", tim_p->tm_sec); count += 2; - s[count++] = ' '; - if (tim_p->tm_hour < 12) - s[count++] = 'A'; - else - s[count++] = 'P'; - - s[count++] = 'M'; } else return 0; break; - case 'R': - if (count < maxsize - 5) - { - sprintf (&s[count], "%.2d:%.2d", tim_p->tm_hour, tim_p->tm_min); - count += 5; - } - else - return 0; - break; - case 'S': + case 'U': if (count < maxsize - 2) { - sprintf (&s[count], "%.2d", - tim_p->tm_sec); + sprintf (&s[count], "%2.2d", + (tim_p->tm_yday + 7 - + tim_p->tm_wday) / 7); count += 2; } else return 0; break; - case 't': + case 'w': if (count < maxsize - 1) - s[count++] = '\t'; + { + sprintf (&s[count], "%1.1d", + tim_p->tm_wday); + count++; + } else return 0; break; - case 'T': - case 'X': - if (count < maxsize - 8) - { - sprintf (&s[count], "%.2d:%.2d:%.2d", tim_p->tm_hour, - tim_p->tm_min, tim_p->tm_sec); - count += 8; - } - else - return 0; - break; - case 'u': - if (count < maxsize - 1) - { - if (tim_p->tm_wday == 0) - s[count++] = '7'; - else - s[count++] = '0' + tim_p->tm_wday; - } - else - return 0; - break; - case 'U': + case 'W': if (count < maxsize - 2) { - sprintf (&s[count], "%.2d", + int wday = (tim_p->tm_wday) ? tim_p->tm_wday - 1 : 6; + sprintf (&s[count], "%2.2d", (tim_p->tm_yday + 7 - - tim_p->tm_wday) / 7); + wday) / 7); count += 2; } else return 0; break; - case 'V': - if (count < maxsize - 2) + case 'x': + if (count < maxsize - 15) { - int adjust = iso_year_adjust (tim_p); - int wday = (tim_p->tm_wday) ? tim_p->tm_wday - 1 : 6; - int week = (tim_p->tm_yday + 10 - wday) / 7; - if (adjust > 0) - week = 1; - else if (adjust < 0) - /* Previous year has 53 weeks if current year starts on - Fri, and also if current year starts on Sat and - previous year was leap year. */ - week = 52 + (4 >= (wday - tim_p->tm_yday - - isleap (tim_p->tm_year - + (YEAR_BASE - 1 - - (tim_p->tm_year < 0 - ? 0 : 2000))))); - sprintf (&s[count], "%.2d", week); - count += 2; + for (i = 0; i < 3; i++) + s[count++] = + dname[tim_p->tm_wday][i]; + s[count++] = ' '; + for (i = 0; i < 3; i++) + s[count++] = + mname[tim_p->tm_mon][i]; + + sprintf (&s[count], + " %.2d %.4d", tim_p->tm_mday, + 1900 + tim_p->tm_year); + count += 8; } else return 0; - break; - case 'w': - if (count < maxsize - 1) - s[count++] = '0' + tim_p->tm_wday; - else - return 0; break; - case 'W': - if (count < maxsize - 2) + case 'X': + if (count < maxsize - 8) { - int wday = (tim_p->tm_wday) ? tim_p->tm_wday - 1 : 6; - sprintf (&s[count], "%.2d", - (tim_p->tm_yday + 7 - wday) / 7); - count += 2; + sprintf (&s[count], + "%2.2d:%2.2d:%2.2d", + tim_p->tm_hour, tim_p->tm_min, + tim_p->tm_sec); + count += 8; } else return 0; @@ -732,66 +405,27 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), case 'y': if (count < maxsize - 2) { - /* Be careful of both overflow and negative years, thanks to - the asymmetric range of years. */ - int year = tim_p->tm_year >= 0 ? tim_p->tm_year % 100 - : abs (tim_p->tm_year + YEAR_BASE) % 100; - sprintf (&s[count], "%.2d", year); + /* The year could be greater than 100, so we need the value + modulo 100. The year could be negative, so we need to + correct for a possible negative remainder. */ + sprintf (&s[count], "%2.2d", + (tim_p->tm_year % 100 + 100) % 100); count += 2; } else return 0; break; case 'Y': - { - /* Length is not known because of %C%y, so recurse. */ - size_t adjust = strftime (&s[count], maxsize - count, - "%C%y", tim_p); - if (adjust > 0) - count += adjust; - else - return 0; - } - break; - case 'z': - if (tim_p->tm_isdst >= 0) - { - if (count < maxsize - 5) - { - long offset; - __tzinfo_type *tz = __gettzinfo (); - TZ_LOCK; - /* The sign of this is exactly opposite the envvar TZ. We - could directly use the global _timezone for tm_isdst==0, - but have to use __tzrule for daylight savings. */ - offset = -tz->__tzrule[tim_p->tm_isdst > 0].offset; - TZ_UNLOCK; - sprintf (&s[count], "%+03ld%.2ld", offset / SECSPERHOUR, - labs (offset / SECSPERMIN) % 60L); - count += 5; - } - else - return 0; - } - break; - case 'Z': - if (tim_p->tm_isdst >= 0) + if (count < maxsize - 4) { - int size; - TZ_LOCK; - size = strlen(_tzname[tim_p->tm_isdst > 0]); - for (i = 0; i < size; i++) - { - if (count < maxsize - 1) - s[count++] = _tzname[tim_p->tm_isdst > 0][i]; - else - { - TZ_UNLOCK; - return 0; - } - } - TZ_UNLOCK; + sprintf (&s[count], "%.4d", + 1900 + tim_p->tm_year); + count += 4; } + else + return 0; + break; + case 'Z': break; case '%': if (count < maxsize - 1) @@ -805,8 +439,7 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), else break; } - if (maxsize) - s[count] = '\0'; + s[count] = '\0'; return count; } diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c deleted file mode 100644 index 127772460..000000000 --- a/newlib/libc/time/strptime.c +++ /dev/null @@ -1,446 +0,0 @@ -/* - * Copyright (c) 1999 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of KTH nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#include <stddef.h> -#include <stdio.h> -#include <time.h> -#include <string.h> -#include <ctype.h> -#include <stdlib.h> - -static const char *abb_weekdays[] = { - "Sun", - "Mon", - "Tue", - "Wed", - "Thu", - "Fri", - "Sat", - NULL -}; - -static const char *full_weekdays[] = { - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - NULL -}; - -static const char *abb_month[] = { - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", - NULL -}; - -static const char *full_month[] = { - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", - NULL, -}; - -static const char *ampm[] = { - "am", - "pm", - NULL -}; - -/* - * tm_year is relative this year - */ -const int tm_year_base = 1900; - -/* - * Return TRUE iff `year' was a leap year. - * Needed for strptime. - */ -static int -is_leap_year (int year) -{ - return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0); -} - -/* Needed for strptime. */ -static int -match_string (const char **buf, const char **strs) -{ - int i = 0; - - for (i = 0; strs[i] != NULL; ++i) { - int len = strlen (strs[i]); - - if (strncasecmp (*buf, strs[i], len) == 0) { - *buf += len; - return i; - } - } - return -1; -} - -/* Needed for strptime. */ -static int -first_day (int year) -{ - int ret = 4; - - for (; year > 1970; --year) - ret = (ret + 365 + is_leap_year (year) ? 1 : 0) % 7; - return ret; -} - -/* - * Set `timeptr' given `wnum' (week number [0, 53]) - * Needed for strptime - */ - -static void -set_week_number_sun (struct tm *timeptr, int wnum) -{ - int fday = first_day (timeptr->tm_year + tm_year_base); - - timeptr->tm_yday = wnum * 7 + timeptr->tm_wday - fday; - if (timeptr->tm_yday < 0) { - timeptr->tm_wday = fday; - timeptr->tm_yday = 0; - } -} - -/* - * Set `timeptr' given `wnum' (week number [0, 53]) - * Needed for strptime - */ - -static void -set_week_number_mon (struct tm *timeptr, int wnum) -{ - int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7; - - timeptr->tm_yday = wnum * 7 + (timeptr->tm_wday + 6) % 7 - fday; - if (timeptr->tm_yday < 0) { - timeptr->tm_wday = (fday + 1) % 7; - timeptr->tm_yday = 0; - } -} - -/* - * Set `timeptr' given `wnum' (week number [0, 53]) - * Needed for strptime - */ -static void -set_week_number_mon4 (struct tm *timeptr, int wnum) -{ - int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7; - int offset = 0; - - if (fday < 4) - offset += 7; - - timeptr->tm_yday = offset + (wnum - 1) * 7 + timeptr->tm_wday - fday; - if (timeptr->tm_yday < 0) { - timeptr->tm_wday = fday; - timeptr->tm_yday = 0; - } -} - -/* strptime: roken */ -//extern "C" -char * -//strptime (const char *buf, const char *format, struct tm *timeptr) -_DEFUN (strptime, (buf, format, timeptr), - _CONST char *buf _AND - _CONST char *format _AND - struct tm *timeptr) -{ - char c; - - for (; (c = *format) != '\0'; ++format) { - char *s; - int ret; - - if (isspace (c)) { - while (isspace (*buf)) - ++buf; - } else if (c == '%' && format[1] != '\0') { - c = *++format; - if (c == 'E' || c == 'O') - c = *++format; - switch (c) { - case 'A' : - ret = match_string (&buf, full_weekdays); - if (ret < 0) - return NULL; - timeptr->tm_wday = ret; - break; - case 'a' : - ret = match_string (&buf, abb_weekdays); - if (ret < 0) - return NULL; - timeptr->tm_wday = ret; - break; - case 'B' : - ret = match_string (&buf, full_month); - if (ret < 0) - return NULL; - timeptr->tm_mon = ret; - break; - case 'b' : - case 'h' : - ret = match_string (&buf, abb_month); - if (ret < 0) - return NULL; - timeptr->tm_mon = ret; - break; - case 'C' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_year = (ret * 100) - tm_year_base; - buf = s; - break; - case 'c' : /* %a %b %e %H:%M:%S %Y */ - s = strptime (buf, "%a %b %e %H:%M:%S %Y", timeptr); - if (s == NULL) - return NULL; - buf = s; - break; - case 'D' : /* %m/%d/%y */ - s = strptime (buf, "%m/%d/%y", timeptr); - if (s == NULL) - return NULL; - buf = s; - break; - case 'd' : - case 'e' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_mday = ret; - buf = s; - break; - case 'H' : - case 'k' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_hour = ret; - buf = s; - break; - case 'I' : - case 'l' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - if (ret == 12) - timeptr->tm_hour = 0; - else - timeptr->tm_hour = ret; - buf = s; - break; - case 'j' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_yday = ret - 1; - buf = s; - break; - case 'm' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_mon = ret - 1; - buf = s; - break; - case 'M' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_min = ret; - buf = s; - break; - case 'n' : - if (*buf == '\n') - ++buf; - else - return NULL; - break; - case 'p' : - ret = match_string (&buf, ampm); - if (ret < 0) - return NULL; - if (timeptr->tm_hour == 0) { - if (ret == 1) - timeptr->tm_hour = 12; - } else - timeptr->tm_hour += 12; - break; - case 'r' : /* %I:%M:%S %p */ - s = strptime (buf, "%I:%M:%S %p", timeptr); - if (s == NULL) - return NULL; - buf = s; - break; - case 'R' : /* %H:%M */ - s = strptime (buf, "%H:%M", timeptr); - if (s == NULL) - return NULL; - buf = s; - break; - case 'S' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_sec = ret; - buf = s; - break; - case 't' : - if (*buf == '\t') - ++buf; - else - return NULL; - break; - case 'T' : /* %H:%M:%S */ - case 'X' : - s = strptime (buf, "%H:%M:%S", timeptr); - if (s == NULL) - return NULL; - buf = s; - break; - case 'u' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_wday = ret - 1; - buf = s; - break; - case 'w' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_wday = ret; - buf = s; - break; - case 'U' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - set_week_number_sun (timeptr, ret); - buf = s; - break; - case 'V' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - set_week_number_mon4 (timeptr, ret); - buf = s; - break; - case 'W' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - set_week_number_mon (timeptr, ret); - buf = s; - break; - case 'x' : - s = strptime (buf, "%Y:%m:%d", timeptr); - if (s == NULL) - return NULL; - buf = s; - break; - case 'y' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - if (ret < 70) - timeptr->tm_year = 100 + ret; - else - timeptr->tm_year = ret; - buf = s; - break; - case 'Y' : - ret = strtol (buf, &s, 10); - if (s == buf) - return NULL; - timeptr->tm_year = ret - tm_year_base; - buf = s; - break; - case 'Z' : - /* Unsupported. Just ignore. */ - break; - case '\0' : - --format; - /* FALLTHROUGH */ - case '%' : - if (*buf == '%') - ++buf; - else - return NULL; - break; - default : - if (*buf == '%' || *++buf == c) - ++buf; - else - return NULL; - break; - } - } else { - if (*buf == c) - ++buf; - else - return NULL; - } - } - return (char *)buf; -} - diff --git a/newlib/libc/time/time.tex b/newlib/libc/time/time.tex index 4859404a3..3d6dabb59 100644 --- a/newlib/libc/time/time.tex +++ b/newlib/libc/time/time.tex @@ -18,28 +18,28 @@ the following fields: @table @code @item tm_sec -Seconds, between 0 and 60 inclusive (60 allows for leap seconds). +Seconds. @item tm_min -Minutes, between 0 and 59 inclusive. +Minutes. @item tm_hour -Hours, between 0 and 23 inclusive. +Hours. @item tm_mday -Day of the month, between 1 and 31 inclusive. +Day. @item tm_mon -Month, between 0 (January) and 11 (December). +Month. @item tm_year -Year (since 1900), can be negative for earlier years. +Year (since 1900). @item tm_wday -Day of week, between 0 (Sunday) and 6 (Saturday). +Day of week: the number of days since Sunday. @item tm_yday -Number of days elapsed since last January 1, between 0 and 365 inclusive. +Number of days elapsed since last January 1. @item tm_isdst Daylight Savings Time flag: positive means DST in effect, zero means DST @@ -56,8 +56,6 @@ not in effect, negative means no information about DST is available. * mktime:: Convert time to arithmetic representation * strftime:: Flexible calendar time formatter * time:: Get current calendar time (as single number) -* __tz_lock:: Lock time zone global variables -* tzset:: Set timezone info @end menu @page @@ -86,9 +84,3 @@ not in effect, negative means no information about DST is available. @page @include time/time.def - -@page -@include time/tzlock.def - -@page -@include time/tzset.def diff --git a/newlib/libc/time/tzlock.c b/newlib/libc/time/tzlock.c deleted file mode 100644 index ccfef7891..000000000 --- a/newlib/libc/time/tzlock.c +++ /dev/null @@ -1,56 +0,0 @@ -/* -FUNCTION -<<__tz_lock>>, <<__tz_unlock>>---lock time zone global variables - -INDEX - __tz_lock -INDEX - __tz_unlock - -ANSI_SYNOPSIS - #include "local.h" - void __tz_lock (void); - void __tz_unlock (void); - -TRAD_SYNOPSIS - void __tz_lock(); - void __tz_unlock(); - -DESCRIPTION -The <<tzset>> facility functions call these functions when they need to -ensure the values of global variables. The version of these routines -supplied in the library use the lock API defined in sys/lock.h. If multiple -threads of execution can call the time functions and give up scheduling in -the middle, then you you need to define your own versions of these functions -in order to safely lock the time zone variables during a call. If you do -not, the results of <<localtime>>, <<mktime>>, <<ctime>>, and <<strftime>> -are undefined. - -The lock <<__tz_lock>> may not be called recursively; that is, -a call <<__tz_lock>> will always lock all subsequent <<__tz_lock>> calls -until the corresponding <<__tz_unlock>> call on the same thread is made. -*/ - -#include <_ansi.h> -#include "local.h" -#include <sys/lock.h> - -#ifndef __SINGLE_THREAD__ -__LOCK_INIT(static, __tz_lock_object); -#endif - -_VOID -_DEFUN_VOID (__tz_lock) -{ -#ifndef __SINGLE_THREAD__ - __lock_acquire(__tz_lock_object); -#endif -} - -_VOID -_DEFUN_VOID (__tz_unlock) -{ -#ifndef __SINGLE_THREAD__ - __lock_release(__tz_lock_object); -#endif -} diff --git a/newlib/libc/time/tzset.c b/newlib/libc/time/tzset.c deleted file mode 100644 index c70e3ee6e..000000000 --- a/newlib/libc/time/tzset.c +++ /dev/null @@ -1,72 +0,0 @@ -/* -FUNCTION -<<tzset>>---set timezone characteristics from TZ environment variable - -INDEX - tzset - -ANSI_SYNOPSIS - #include <time.h> - void tzset(void); - void _tzset_r (struct _reent *); - -TRAD_SYNOPSIS - #include <time.h> - void tzset(); - void _tzset_r (reent_ptr) - struct _reent *reent_ptr; - -DESCRIPTION -<<tzset>> examines the TZ environment variable and sets up the three -external variables: <<_timezone>>, <<_daylight>>, and <<tzname>>. The -value of <<_timezone>> shall be the offset from the current time zone -to GMT. The value of <<_daylight>> shall be 0 if there is no daylight -savings time for the current time zone, otherwise it will be non-zero. -The <<tzname>> array has two entries: the first is the name of the -standard time zone, the second is the name of the daylight-savings time -zone. - -The TZ environment variable is expected to be in the following POSIX -format: - - stdoffset1[dst[offset2][,start[/time1],end[/time2]]] - -where: std is the name of the standard time-zone (minimum 3 chars) - offset1 is the value to add to local time to arrive at Universal time - it has the form: hh[:mm[:ss]] - dst is the name of the alternate (daylight-savings) time-zone (min 3 chars) - offset2 is the value to add to local time to arrive at Universal time - it has the same format as the std offset - start is the day that the alternate time-zone starts - time1 is the optional time that the alternate time-zone starts - (this is in local time and defaults to 02:00:00 if not specified) - end is the day that the alternate time-zone ends - time2 is the time that the alternate time-zone ends - (it is in local time and defaults to 02:00:00 if not specified) - -Note that there is no white-space padding between fields. Also note that -if TZ is null, the default is Universal GMT which has no daylight-savings -time. If TZ is empty, the default EST5EDT is used. - -The function <<_tzset_r>> is identical to <<tzset>> only it is reentrant -and is used for applications that use multiple threads. - -RETURNS -There is no return value. - -PORTABILITY -<<tzset>> is part of the POSIX standard. - -Supporting OS subroutine required: None -*/ - -#include <_ansi.h> -#include <reent.h> -#include <time.h> -#include "local.h" - -_VOID -_DEFUN_VOID (tzset) -{ - _tzset_r (_REENT); -} diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c deleted file mode 100644 index 36b87d7b2..000000000 --- a/newlib/libc/time/tzset_r.c +++ /dev/null @@ -1,199 +0,0 @@ -#include <_ansi.h> -#include <reent.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/time.h> -#include "local.h" - -static char __tzname_std[11]; -static char __tzname_dst[11]; -static char *prev_tzenv = NULL; - -_VOID -_DEFUN (_tzset_r, (reent_ptr), - struct _reent *reent_ptr) -{ - char *tzenv; - unsigned short hh, mm, ss, m, w, d; - int sign, n; - int i, ch; - __tzinfo_type *tz = __gettzinfo (); - - if ((tzenv = _getenv_r (reent_ptr, "TZ")) == NULL) - { - TZ_LOCK; - _timezone = 0; - _daylight = 0; - _tzname[0] = "GMT"; - _tzname[1] = "GMT"; - TZ_UNLOCK; - return; - } - - TZ_LOCK; - - if (prev_tzenv != NULL && strcmp(tzenv, prev_tzenv) == 0) - { - TZ_UNLOCK; - return; - } - - free(prev_tzenv); - prev_tzenv = _malloc_r (reent_ptr, strlen(tzenv) + 1); - if (prev_tzenv != NULL) - strcpy (prev_tzenv, tzenv); - - /* ignore implementation-specific format specifier */ - if (*tzenv == ':') - ++tzenv; - - if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0) - { - TZ_UNLOCK; - return; - } - - tzenv += n; - - sign = 1; - if (*tzenv == '-') - { - sign = -1; - ++tzenv; - } - else if (*tzenv == '+') - ++tzenv; - - mm = 0; - ss = 0; - - if (sscanf (tzenv, "%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n) < 1) - { - TZ_UNLOCK; - return; - } - - tz->__tzrule[0].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh); - _tzname[0] = __tzname_std; - tzenv += n; - - if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_dst, &n) <= 0) - { - _tzname[1] = _tzname[0]; - TZ_UNLOCK; - return; - } - else - _tzname[1] = __tzname_dst; - - tzenv += n; - - /* otherwise we have a dst name, look for the offset */ - sign = 1; - if (*tzenv == '-') - { - sign = -1; - ++tzenv; - } - else if (*tzenv == '+') - ++tzenv; - - hh = 0; - mm = 0; - ss = 0; - - if (sscanf (tzenv, "%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n) <= 0) - tz->__tzrule[1].offset = tz->__tzrule[0].offset - 3600; - else - tz->__tzrule[1].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh); - - tzenv += n; - - for (i = 0; i < 2; ++i) - { - if (*tzenv == ',') - ++tzenv; - - if (*tzenv == 'M') - { - if (sscanf (tzenv, "M%hu%n.%hu%n.%hu%n", &m, &n, &w, &n, &d, &n) != 3 || - m < 1 || m > 12 || w < 1 || w > 5 || d > 6) - { - TZ_UNLOCK; - return; - } - - tz->__tzrule[i].ch = 'M'; - tz->__tzrule[i].m = m; - tz->__tzrule[i].n = w; - tz->__tzrule[i].d = d; - - tzenv += n; - } - else - { - char *end; - if (*tzenv == 'J') - { - ch = 'J'; - ++tzenv; - } - else - ch = 'D'; - - d = strtoul (tzenv, &end, 10); - - /* if unspecified, default to US settings */ - if (end == tzenv) - { - if (i == 0) - { - tz->__tzrule[0].ch = 'M'; - tz->__tzrule[0].m = 4; - tz->__tzrule[0].n = 1; - tz->__tzrule[0].d = 0; - } - else - { - tz->__tzrule[1].ch = 'M'; - tz->__tzrule[1].m = 10; - tz->__tzrule[1].n = 5; - tz->__tzrule[1].d = 0; - } - } - else - { - tz->__tzrule[i].ch = ch; - tz->__tzrule[i].d = d; - } - - tzenv = end; - } - - /* default time is 02:00:00 am */ - hh = 2; - mm = 0; - ss = 0; - n = 0; - - if (*tzenv == '/') - sscanf (tzenv, "/%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n); - - tz->__tzrule[i].s = ss + SECSPERMIN * mm + SECSPERHOUR * hh; - - tzenv += n; - } - - __tzcalc_limits (tz->__tzyear); - _timezone = tz->__tzrule[0].offset; - _daylight = tz->__tzrule[0].offset != tz->__tzrule[1].offset; - - TZ_UNLOCK; -} - - - - - diff --git a/newlib/libc/time/tzvars.c b/newlib/libc/time/tzvars.c deleted file mode 100644 index d1f17649b..000000000 --- a/newlib/libc/time/tzvars.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <time.h> - -/* Global timezone variables. */ - -/* Default timezone to GMT */ -char *_tzname[2] = {"GMT", "GMT"}; -int _daylight = 0; -long _timezone = 0; - - |