aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/time/strftime.c
AgeCommit message (Collapse)AuthorFilesLines
2022-10-29strftime/wcsftime: use STRLEN, not strlenCorinna Vinschen1-1/+1
Commit 737e2004a3bb accidentally introduced a call to strlen in code used with wide character strings in case of wcsftime. Use STRLEN instead. Fixes: 737e2004a3bb ("strftime.c(__strftime): add %q, %v, tests; tweak %Z doc") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-25strftime.c(__strftime): add %q, %v, tests; tweak %Z docBrian Inglis1-3/+55
%q GNU quarter year 1-4 %v BSD/OSX/Ruby VMS/Oracle %e-%b-%Y %Z change time zone *name* to *abbreviation*
2018-08-08newlib: strftime: fix over-enthusiastic fix from 0283642f35ceCorinna Vinschen1-1/+2
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: fix various gcc warningsCorinna Vinschen1-3/+0
* unused variables * potentially used uninitialized * suggested bracketing * misleading indentation Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: strftime: fix gcc warning on __ctlocCorinna Vinschen1-5/+3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-01-17ansification: remove _DEFUNYaakov Selkowitz1-4/+2
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _CONSTYaakov Selkowitz1-4/+4
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-01-17ansification: remove _ANDYaakov Selkowitz1-3/+3
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-12-01time: remove TRAD_SYNOPSISYaakov Selkowitz1-9/+1
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2016-10-22get_alt_digits: Fix typo in allocationCorinna Vinschen1-1/+1
adi->digit is an array of CHAR *, not of CHAR **. Fixes Coverity CID 60043 Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-23Implement GNU extension wcsftime_lCorinna Vinschen1-3/+2
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-16Use era_info_t and alt_digits_t on _WANT_C99_TIME_FORMATS targets onlyCorinna Vinschen1-2/+12
Using era_info_t and alt_digits_t indiscriminately in strftime and strftime_l breaks targets not wanting C99 time formats. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-08-15Rename __get_locale_XXX to __get_XXX_locale to use unified naming schemeCorinna Vinschen1-1/+1
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
2016-08-15Implement per-locale string functionsCorinna Vinschen1-38/+62
strcasecmp_l, strcoll_l, strncasecmp_l, strxfrm_l, wcscasecmp_l, wcscoll_l, wcstrncasecmp_l, wcstrxfrm_l, strftime_l. Add missing CHEWOUT_FILES from previous patch. TODO: strfmon_l. Signed-off by: Corinna Vinschen <corinna@vinschen.de>
2016-08-15POSIX-1.2008 per-thread locales, groundwork part 2Corinna Vinschen1-2/+2
Move all locale category structure definitions into setlocale.h and remove other headers in locale subdir. Create inline accessor functions for current category struct pointers and use throughout. Use pointers to "C" locale category structs by default in __global_locale. Signed-off by: Corinna Vinschen <corinna@vinschen.de>
2015-10-27strftime: Add support for %s (seconds since epoch)Brian Inglis1-25/+99
* libc/time/strftime.c (__strftime): add support for %s (seconds from Unix epoch). Fix whitespaces. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-04-23Avoid excessive locking and calling tzset in time functions.Corinna Vinschen1-2/+14
* libc/time/lcltime_r.c (localtime_r): Call _tzset_unlocked inside TZ lock. * libc/time/mktime.c (mktime): Ditto. * libc/time/strftime.c (strftime, wcsftime): Ditto. Guard against calling _tzset_unlocked more than once (baring recursion). Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-04-23Move tzset calls to time functions.Craig Howland1-0/+2
* libc/stdlib/setenv_r.c (_setenv_r): Remove tzset() call for TZ definition. * libc/time/lcltime_r.c (localtime_r): Add tzset() call * libc/time/mktime.c (mktime): Ditto. * libc/time/strftime.c (strftime, wcsftime): Ditto. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-04-23strftime: use tzname if TM_ZONE is NULLYaakov Selkowitz1-3/+3
This avoids a strlen(NULL) crash a few lines later. * libc/time/strftime.c (strftime) <%Z>: Initialize tznam to NULL. Use _tzname as fallback if TM_ZONE is NULL.
2015-01-08 * libc/time/strftime.c (__strftime): Utilize __TM_GMTOFF and __TM_ZONECorinna Vinschen1-6/+32
on systems where available. On Cygwin, call function to get values. Add comment to explain why. Drop TZ_LOCK/TZ_UNLOCK in 'z' case since it's not necessary. In 'Z' case, add a comment to document a potential codeset problem.
2014-09-04 * libc/time/clock.c (clock): Fix warnings about signed-unsignedCorinna Vinschen1-3/+3
comparisons. * libc/time/strftime.c (strftime): Likewise. * libc/time/strptime.c (match_string): Fix warning about discarding 'restrict' qualifier from pointer target type.
2013-11-262013-11-25 Joel Sherrill <joel.sherrill@oarcorp.com>Joel Sherrill1-1/+1
* libc/iconv/lib/iconv.c, libc/time/strftime.c: Change "restrict<" to "restrict <" to fix formatting.
2013-11-252013-11-25 Joel Sherrill <joel.sherrill@oarcorp.com>Joel Sherrill1-2/+2
* libc/iconv/lib/iconv.c, libc/time/strftime.c: Change "restrict<" to "restrict <" to fix formatting.
2013-11-252013-11-25 Sahil Patnayakuni <sahil.patnayakuni@gmail.com>Joel Sherrill1-8/+9
* libc/include/time.h (time): Add restrict keyword. * libc/include/wchar.h (wcsftime): Add restrict keyword. * libc/time/asctime_r.c (asctime_r): Same. * libc/time/gmtime_r.c (gmtime_r): Same. * libc/time/lcltime_r.c (lcltime_r): Same. * libc/time/strftime.c (strftime): Same. * libc/time/strptime.c (strptime): Same. * libc/sys/linux/linuxthreads/timer_create.c (timer_create): Same. * libc/sys/linux/linuxthreads/timer_settime.c (timer_settime): Same.
2012-08-10 * libc/stdlib/btowc.c (btowc): Cast to avoid compiler warning.Corinna Vinschen1-1/+1
* libc/search/hash_buf.c (__get_buf): Initialize local vars to avoid compiler warning. * libc/stdio/fgets.c (_fgets_r): Ditto. * libc/time/strftime.c (strftime): Ditto.
2011-12-12 * libc/time/strftime.c (get_era_info): Fix off-by-one error in monthCorinna Vinschen1-3/+3
calculation.
2011-06-14 * libc/time/asctime_r.c (asctime_r): Replace call to sprintf with callCorinna Vinschen1-0/+1
to siprintf. * libc/time/strftime.c: Define snprintf to sniprintf in multibyte case. * libc/time/tzset_r.c: Define sscanf to siscanf.
2010-04-28 Extend locale support to maintain wide char values of native stringsCorinna Vinschen1-35/+81
if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/include/langinfo.h (enum __nl_item): New type. Define all native values accessible through nl_langinfo. Define previously existing POSIX-compatible values as macros as well. * libc/include/stdlib.h (__mb_cur_max): Drop declaration. (__locale_mb_cur_max): Declare. (MB_CUR_MAX): Re-define calling __locale_mb_cur_max. * libc/locale/Makefile.am (ELIX_SOURCES): Add lctype.c. * libc/locale/Makefile.in: Regenerate. * libc/locale/lctype.c: New file to define and load LC_CTYPE category. * libc/locale/lctype.h: New file, matching header. * libc/locale/lmessages.c (_C_messages_locale): Add default values for wide char members. (__messages_load_locale): Add _C_messages_locale in call to __set_lc_messages_from_win. * libc/locale/lmessages.h (struct lc_messages_T): Add wide char members. * libc/locale/lmonetary.c (_C_monetary_locale): Add default values for wide char members. (__monetary_load_locale): Add _C_monetary_locale in call to __set_lc_monetary_from_win. * libc/locale/lmonetary.h (struct lc_monetary_T): Add wide char members. Add numerical values for international currency formatting per POSIX-1.2008, if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/locale/lnumeric.c (_C_numeric_locale): Add default values for wide char members. (__numeric_load_locale): Add _C_numeric_locale in call to __set_lc_numeric_from_win. * libc/locale/lnumeric.h (struct lc_numeric_T): Add wide char members. * libc/locale/locale.c (loadlocale): Return doing nothing if category locale didn't change. Convert category if chain to switch statement. Call __ctype_load_locale in LC_CTYPE case. (__locale_charset): Add (but disable for now) returning codeset from __get_current_ctype_locale. (__locale_mb_cur_max): Add (but disable for now) returning mb_cur_max from __get_current_ctype_locale. (__locale_msgcharset): Add returning codeset from __get_current_messages_locale. (_localeconv_r): Accommodate int_XXX values. * libc/locale/nl_langinfo.c (nl_ext): New array to define what is to be returned for non-POSIX values. (nl_Langinfo): Return correct codeset for each locale category. Return extended values if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/locale/timelocal.c (_C_time_locale): Add default values for wide char members. (__time_load_locale): Add _C_time_locale in call to __set_lc_time_from_win. * libc/locale/timelocal.h (struct lc_time_T): Add wide char members. * libc/stdio/vfwprintf.c (_VFWPRINTF_R): Use wide char decimal point and thousands_sep if __HAVE_LOCALE_INFO_EXTENDED__ is defined. * libc/time/strftime.c: Rework to accommodate availability of wide char strings in LC_TIME category if __HAVE_LOCALE_INFO_EXTENDED__ is defined.
2010-04-22* libc/Makefile.am (SUBDEFS): Add LIBC_POSIX_DEF.DJ Delorie1-1/+1
(libc.info): Add posix.texi. (libc.dvi): Likewise. (stmp-posix): New. (posix.texi): New. (libc_TEXINFOS): Add posix.texi. * libc/configure.in (LIBC_POSIX_LIB, LIBC_POSIX_DEF): Add tests. * libc/libc.texinfo: Include posix.texi * libc/locale/locale.c: Fix texinfo typo. * libc/time/strftime.c: Fix texinfo typo. * libc/configure: Regenerate. * libc/Makefile.in: Regenerate. * libc/argz/Makefile.in: Regenerate. * libc/ctype/Makefile.in: Regenerate. * libc/errno/Makefile.in: Regenerate. * libc/iconv/Makefile.in: Regenerate. * libc/iconv/ccs/Makefile.in: Regenerate. * libc/iconv/ccs/binary/Makefile.in: Regenerate. * libc/iconv/ces/Makefile.in: Regenerate. * libc/iconv/lib/Makefile.in: Regenerate. * libc/locale/Makefile.in: Regenerate. * libc/misc/Makefile.in: Regenerate. * libc/posix/Makefile.in: Regenerate. * libc/reent/Makefile.in: Regenerate. * libc/search/Makefile.in: Regenerate. * libc/signal/Makefile.in: Regenerate. * libc/stdio/Makefile.in: Regenerate. * libc/stdio64/Makefile.in: Regenerate. * libc/stdlib/Makefile.in: Regenerate. * libc/string/Makefile.in: Regenerate. * libc/syscalls/Makefile.in: Regenerate. * libc/time/Makefile.in: Regenerate. * libc/unix/Makefile.in: Regenerate. * libc/xdr/Makefile.in: Regenerate.
2010-02-26 * libc/time/strftime.c: Add support for era and alt_digits data fromCorinna Vinschen1-96/+611
LC_TIME locale category. Conditionalize using _WANT_C99_TIME_FORMATS flag. (STRTOUL): Define differently for building strftime or wcsftime. (STRCPY): Ditto. (STRCHR): Ditto. (STRLEN): Ditto. (CHECK_LENGTH): Define to simplify code. (era_info_t): New type to store era info. (get_era_info): New function to fetch era info matching incoming struct tm. (free_era_info): New function to free era info. (alt_digits_t): New type to store alternative digits. (get_alt_digits): New function to convert alt_digits string into alt_digits_t structure. (free_alt_digits): New function to free alt_digits info. (conv_to_alt_digits): New function to convert unsigned value into alternative digits. (strftime): Conditionalize on _WANT_C99_TIME_FORMATS. If _WANT_C99_TIME_FORMATS is defined, define as just a wrapper function providing era_info and alt_digits pointers and call ... (__strftime): Rename from strftime and make static if _WANT_C99_TIME_FORMATS is defined. Add parameters for era_info and alt_digits pointers. Handle conversion modifiers according to POSIX-1.2008. Redefine %F and %Y according to POSIX. Add default case to allow to bail out on invalid conversion specifiers. * libc/include/sys/config.h: Move Cygwin build flags to Cygwin's config.h. * libc/include/stdio.h: Remove __CYGWIN_USE_BIG_TYPES__ condition.
2010-01-22 * libc/locale/lmonetary.c (__monetary_load_locale): Take additionalCorinna Vinschen1-80/+88
parameters for wide char to multibyte conversion. Call __set_lc_monetary_from_win on Cygwin. * libc/locale/lmonetary.h: Make C++-safe. (__monetary_load_locale): Change declaration. * libc/locale/lnumeric.c (__numeric_load_locale): Take additional parameters for wide char to multibyte conversion. Call __set_lc_numeric_from_win on Cygwin. * libc/locale/lnumeric.h: Make C++-safe. (__numeric_load_locale): Change declaration. * libc/locale/locale.c (lconv): De-constify for Cygwin. (__set_charset_from_locale): Rename from __set_charset_from_codepage. Take locale as parameter instead of a codepage. (loadlocale): Allow "EUC-JP" for "EUCJP" and "EUC-KR" for "EUCKR". Change documnetation accordingly. Enable LC_COLLATE, LC_MONETARY, LC_NUMERIC, and LC_TIME handling on Cygwin. (_localeconv_r): On Cygwin, copy values from monetary and numeric domain if change has been noted. * libc/locale/nl_langinfo.c (nl_langinfo): Accommodate change of am/pm layout in struct lc_time_T. * libc/locale/timelocal.c (_C_time_locale): Accommodate redefinition of am/pm members. (__time_load_locale): Take additional parameters for wide char to multibyte conversion. Call __set_lc_time_from_win on Cygwin. * libc/locale/timelocal.h: Make C++-safe. (struct lc_time_T): Convert am and pm to a am_pm array for easier consumption by strftime and strptime. (__time_load_locale): Change declaration. * libc/time/strftime.c: Change documentation to reflect changes to strftime. Remove locale constant strings in favor of access to locale-specifc data. (_ctloc): Define access method for locale-specifc data. (TOLOWER): Define for tolower conversion. (strftime): Throughout, convert locale-specific formats to use locale-specific data. Add GNU-specific "%P" format. * libc/time/strptime.c: Remove locale constant strings in favor of access to locale-specifc data. (_ctloc): Define access method for locale-specifc data. (strptime): Throughout, convert locale-specific formats to use locale-specific data.
2009-03-12 * libc/stdio/swprintf.c (_swprintf_r, swprintf):Corinna Vinschen1-52/+56
correct how terminating L'\0' is added; change return to match standard for when output does not fit; some corrections and enhancements to the docs. * libc/stdio/vswprintf.c (_vswprintf_r): ditto, except for docs. * libc/stdio/vfwprintf.c: some corrections to the docs and some enhancements to comments. (No code changes.) * libc/time/strftime.c: Correct some problems that made wcsftime() not work correctly: work properly with swprintf returns that are different from snprintf returns, correct test vector lengths for when sizeof(wchar_t) > 1. * libc/stdio/sprintf.c: Some documentation and comment corrections and enhancements to match those done to swprintf.c.
2009-03-09 * libc/time/strftime.c: Adapt for dual-purpose use so not onlyCorinna Vinschen1-264/+666
defines strftime(), but can also define wcsftime(); add optional test package; speed up %Y handling. * libc/time/wcsftime.c: New file, defining wcsftime() (albeit indirectly by including strftime.c) and its documentation. * libc/time/time.tex: Enhance tm_isdst explanation, change strftime description to match modified description in strftime.c * libc/time/Makefile.am: Add wcsftime.c and wcsftime.def. Add a rule so that wcsftime.o gets rebuilt when strftime changes. * libc/time/Makefile.in: Regenerate. * libc/include/wchar.h (wcsftime): Declare.
2005-02-252005-02-25 Eric Blake <ebb9@byu.net>Jeff Johnston1-7/+9
* libc/include/time.h (__tzrule_struct): Make offset long, since a 16-bit int overflows on a 12-hour offset. * libc/sys/linux/include/time.h: Ditto. * libc/time/mktime.c (mktime): Use new type of __tzrule.offset. * libc/time/mktm_r.c: Ditto. * libc/time/gettzinfo.c: Ditto. * libc/time/strftime.c (strftime): Fix '%x' to deal with negative years. Fix '%z' to use long, not int.
2005-02-24Fix minor typoJoshua Daniel Franklin1-3/+3
2005-02-232005-02-23 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-1/+2
* libc/include/time.h [!CYGWIN](_timezone): Change to long. (__tzrule_type, __tzinfo_type): New types. (__gettzinfo): New function. * libc/sys/linux/include/time.h: Ditto. * libc/time/Makefile.am: Add gettzinfo.c. * libc/time/Makefile.in: Regenerated. * libc/time/local.h: Moved __tzrule_type to time.h. * libc/time/mktime.c: Call __gettzinfo to reference __tznorth, __tzyear, and __tzrule array. * libc/time/mktm_r.c: Ditto. * libc/time/strftime.c: Ditto. * libc/time/tzset_r.c: Ditto. Also remove definition of __tzrule which is now in gettzinfo.c. Change _timezone references to not cast to time_t. * libc/time/gettzinfo.c: New file.
2005-02-162005-02-16 Eric Blake <ebb9@byu.net>Jeff Johnston1-165/+416
* libc/time/time.tex: Improve the documentation. * libc/time/strftime.c: Improve the documentation. (iso_year_adjust): New helper function. (strftime): Simplify '%E' and '%O'. Change '%c' to use recursion. Fix '%C', '%y', and '%Y' to deal with years with more than 4 characters. Combine '%d' and '%e'. Implement '%D', '%F', '%g', '%G', '%n', '%R', '%t', '%T', '%u', '%V', '%X', and '%z'. Avoid core dumps on valid inputs (maxsize == 0, or tim_p->tm_isdst > 1).
2005-01-202005-01-20 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-17/+96
* libc/time/strftime.c (strftime): Change %r and %x to be compliant to POSIX standard for "C" locale. Allow %E and %O modifiers to be ignored as long as they precede valid specifiers according to POSIX.
2003-01-15* libc/time/strftime.c (strftime): Add '%h' and '%l, %k' GNU extensions.Christopher Faylor1-2/+5
2002-06-21 * libc/time/strftime.c (strftime): Add %e format specifier.Corinna Vinschen1-0/+13
2002-04-172002-04-17 Jeff Johnston <jjohnstn@redhat.com>Jeff Johnston1-3/+21
* libc/include/time.h (tzset, _tzset_r): Added prototypes. (strptime): Moved prototype to be within !__STRICT_ANSI__. (_tzname, _daylight, _timezone): No long __CYGWIN__ only. (tzname): Defined for all platforms. (daylight, timezone): Defined only for CYGWIN. * libc/sys/linux/machine/i386/crt0.c: Add call to tzset() after environment set up. * libc/stdlib/setenv_r.c (_setenv_r): Call tzset() if the TZ environment variable is set. * libc/time/Makefile.am: Add support for tzset.c, tzlock.c, and tzset_r.c. * libc/time/Makefile.in: Regenerated. * libc/time/gmtime.c (gmtime): Changed to call gmtime_r. * libc/time/gmtime_r.c (gmtime_r): Changed to call _mktm_r. * libc/time/lcltime_r.c (lcltime_r): Ditto. * libc/time/local.h: New local header file. * libc/time/mktime.c (mktime): Add timezone support. * libc/time/mktm_r.c: New file which is the common engine for gmtime_r and lcltime_r. This code has timezone support. * libc/time/strftime.c (strftime): Add %Z timezone support. * libc/time/tzlock.c: New file containing timezone lock stubs. * libc/time/tzset.c: New file containing tzset() routine. * libc/time/tzset_r.c: New file containing _tzset_r and internal routine for calculating timezone changes for specified year.
2001-09-13Thu Sep 13 08:49:49 2001 Jason Tishler <jason@tishler.net>Jeff Johnston1-2/+3
* strftime.c (strftime): Fix "%W" implementation to properly handle Mondays too.
2000-02-17import newlib-2000-02-17 snapshotChristopher Faylor1-0/+444