Re: Bash unable to print epoch timestamp
On Oct 28 17:20, Brian Inglis wrote: > Corinna Vinschen cygwin.com> writes: > > On Oct 26 19:16, Brian Inglis wrote: > > > Sorry - redo with the file existing! > > > > No worries, I applied your other patch since it also cleaned up some > > whitespaces and, for some reason, the below patch didn't apply cleanly. > > Email paste may have converted tabs to spaces - need to work out how to > email inline text attachments without tab expansion in tbird - paste on > gmane (below) seems to retain tabs - may try that in future. > > > There was just one problem: > > > > > + { > > > + long offset;/* offset < 0 => W of GMT, > 0 => E of GMT: > > > + offset = 0;subtract to get UTC */ > > > > This setting the offset to 0 is necessary, but commented out. Typo? > > I fixed this before committing the patch. > > Thanks - total brain fart - Doh! Interesting that gcc -Wall -Wextra did not > catch this - used to be reliable warning about conditionally uninitialized > variables! > > Please check that the second set of tests in Vec1 includes the following, as > it was not in my very first patch email, which you may not have received: > @@ -1502,6 +1575,7 @@ const struct test Vec1[] = { > { CQ("%p"), 2+1, EXP(CQ("PM")) }, > { CQ("%r"), 11+1, EXP(CQ("11:01:13 PM")) }, > { CQ("%R"), 5+1, EXP(CQ("23:01")) }, > + { CQ("%s"), 2+1, EXP(CQ("1215054073")) }, > { CQ("%S"), 2+1, EXP(CQ("13")) }, > { CQ("%t"), 1+1, EXP(CQ("\t")) }, > { CQ("%T"), 8+1, EXP(CQ("23:01:13")) }, Check. This was in your patch so it's upstream now. Thanks, Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat pgpJ2Uo9Z5615.pgp Description: PGP signature
Re: Bash unable to print epoch timestamp
Corinna Vinschen cygwin.com> writes: > > On Oct 26 19:16, Brian Inglis wrote: > > On 2015-10-26 11:34, Brian Inglis wrote: > > >Third time lucky - pasting inline into email and resending to all previous lists. > > > > > >Please note that conversion into too-small buffer size in regression test may not have expected result! > > > > > >Tried to build with below and variants: > > >gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf > -I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o strftime-s-test strftime.c > > >gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, __get_current_time_locale, > __tz_lock, __tz_unlock, > > >_tzset_unlocked > > > > > >Build stc with std cmdline and current strftime works and does demo issue. > > > > Sorry - redo with the file existing! > > No worries, I applied your other patch since it also cleaned up some > whitespaces and, for some reason, the below patch didn't apply cleanly. Email paste may have converted tabs to spaces - need to work out how to email inline text attachments without tab expansion in tbird - paste on gmane (below) seems to retain tabs - may try that in future. > There was just one problem: > > > + { > > + long offset;/* offset < 0 => W of GMT, > 0 => E of GMT: > > + offset = 0;subtract to get UTC */ > > This setting the offset to 0 is necessary, but commented out. Typo? > I fixed this before committing the patch. Thanks - total brain fart - Doh! Interesting that gcc -Wall -Wextra did not catch this - used to be reliable warning about conditionally uninitialized variables! Please check that the second set of tests in Vec1 includes the following, as it was not in my very first patch email, which you may not have received: @@ -1502,6 +1575,7 @@ const struct test Vec1[] = { { CQ("%p"), 2+1, EXP(CQ("PM")) }, { CQ("%r"), 11+1, EXP(CQ("11:01:13 PM")) }, { CQ("%R"), 5+1, EXP(CQ("23:01")) }, + { CQ("%s"), 2+1, EXP(CQ("1215054073")) }, { CQ("%S"), 2+1, EXP(CQ("13")) }, { CQ("%t"), 1+1, EXP(CQ("\t")) }, { CQ("%T"), 8+1, EXP(CQ("23:01:13")) }, -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Re: Bash unable to print epoch timestamp
On Oct 26 19:16, Brian Inglis wrote: > On 2015-10-26 11:34, Brian Inglis wrote: > >Third time lucky - pasting inline into email and resending to all previous > >lists. > > > >Please note that conversion into too-small buffer size in regression test > >may not have expected result! > > > >Tried to build with below and variants: > >gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf > >-I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o > >strftime-s-test strftime.c > >gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, > >__get_current_time_locale, __tz_lock, __tz_unlock, > >_tzset_unlocked > > > >Build stc with std cmdline and current strftime works and does demo issue. > > Sorry - redo with the file existing! No worries, I applied your other patch since it also cleaned up some whitespaces and, for some reason, the below patch didn't apply cleanly. There was just one problem: > + { > + long offset;/* offset < 0 => W of GMT, > 0 => E of GMT: > + offset = 0;subtract to get UTC */ This setting the offset to 0 is necessary, but commented out. Typo? I fixed this before committing the patch. Thanks again, Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat pgpN7qDBa9ixd.pgp Description: PGP signature
Re: Bash unable to print epoch timestamp
On Oct 26 19:16, Brian Inglis wrote: > On 2015-10-26 11:34, Brian Inglis wrote: > >Third time lucky - pasting inline into email and resending to all previous > >lists. > > > >Please note that conversion into too-small buffer size in regression test > >may not have expected result! > > > >Tried to build with below and variants: > >gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf > >-I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o > >strftime-s-test strftime.c > >gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, > >__get_current_time_locale, __tz_lock, __tz_unlock, > >_tzset_unlocked > > > >Build stc with std cmdline and current strftime works and does demo issue. > > Sorry - redo with the file existing! No worries, I applied your other patch since it also cleaned up some whitespaces and, for some reason, the below patch didn't apply cleanly. There was just one problem: > + { > + long offset;/* offset < 0 => W of GMT, > 0 => E of GMT: > + offset = 0;subtract to get UTC */ This setting the offset to 0 is necessary, but commented out. Typo? I fixed this before committing the patch. Thanks again, Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat pgpt_K_dG1abv.pgp Description: PGP signature
Re: Bash unable to print epoch timestamp
Brian, ping? On Oct 22 10:46, Corinna Vinschen wrote: > Hi Brian, > > On Oct 22 07:03, Brian Inglis wrote: > > Brian Inglis SystematicSw.ab.ca> writes: > > > > > > > > Don Harrop effx.us> writes: > > > > Bash outputs no value when using it's built in method of printing an > > > > "epoch" timestamp. > > > > BashCommandLine#: printf '%(%s)T' -1 > > > > > > bash printf depends on underlying strftime in newlib, which does not > > > support > > > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that > > > is presumably not defined in the config, as %s is not shown in man > > > strftime. > > > Workaround for now is use > > > date +%s > > > for current time, and > > >date -d $(printf '%(%T)T' -2) +%s > > > for shell invocation time. > > > > > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that > > Wrong! Misread the code, strftime %s is not supported! > > > > STC and suggested patch appended (posting from gmane), compiles, but can't > > build STC as ld fails with undef refs, and I don't know all the correct > > LD..., -L and -l incantations. Email me for original files. > > Cool, thanks for the patch. Unfortunately it doesn't apply cleanly. > There are several unexpected line wraps and there's this: > > > --- a/newlib/time/strftime.c2015-08-20 03:39:24.0 -0600 > > +++ b/newlib/time/strftime.c2015-10-21 20:15:22.367453000 -0600 > > How did this happen? If you checkout the newlib-cygwin git repo, > strftime.c is under newlib/libc/time, not under newlib/time :o > > Would you mind to attach a patch generated with git format-patch? > > > Thanks in advance, > Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat pgpX0rToigHaI.pgp Description: PGP signature
Re: Bash unable to print epoch timestamp
Forwarded Message Subject: Fwd: Re: Bash unable to print epoch timestamp Date: Fri, 23 Oct 2015 14:32:44 -0600 From: Brian Inglis <brian.ing...@systematicsw.ab.ca> Reply-To: brian.ing...@systematicsw.ab.ca Organisation: Systematic Software To: corinna-cyg...@cygwin.com Already forwarded as below to cygwin and ...patches-allow... - should be HTML free and pass filters? On 2015-10-26 11:34, Brian Inglis wrote: Third time lucky - pasting inline into email and resending to all previous lists. Please note that conversion into too-small buffer size in regression test may not have expected result! Tried to build with below and variants: gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf -I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o strftime-s-test strftime.c gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, __get_current_time_locale, __tz_lock, __tz_unlock, _tzset_unlocked Build stc with std cmdline and current strftime works and does demo issue. Sorry - redo with the file existing! -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada - >8 - 8< - /* newlib/libc/time/strftime.c %s format STC */ #include #include int main( int argc, char **argv) { char ss[BUFSIZ] = ""; time_t tt = time( NULL ); struct tm *tp = gmtime( ); tt = mktime( tp ); size_t st = strftime( ss, sizeof ss, "%s", tp); int rc = puts( ss ); st = strftime( ss, sizeof ss, "%T", tp); rc = puts( ss ); return rc; } - >8 - 8< - --- a/newlib/ChangeLog 2015-08-20 03:39:23.0 -0600 +++ b/newlib/ChangeLog 2015-10-26 18:50:44.165368900 -0600 @@ -1,3 +1,8 @@ +2015-10-12 Brian Inglis <brian.ing...@systematicsw.ab.ca> + + * libc/time/strftime.c (__strftime): add support for %s (seconds from + Unix epoch) + 2015-08-07 Stefan Wallentowitz <stefan.wallentow...@tum.de> * libc/sys/or1k/mlock.c: Fix exception enable saving --- a/newlib/libc/time/strftime.c 2015-08-20 03:39:24.0 -0600 +++ b/newlib/libc/time/strftime.c 2015-10-26 04:27:12.244016200 -0600 @@ -166,6 +166,10 @@ notations, the result is an empty string o %R The 24-hour time, to the minute. Equivalent to "%H:%M". [tm_min, tm_hour] +o %s +The time elapsed, in seconds, since the start of the Unix epoch at +1970-01-01 00:00:00 UTC. + o %S The second, formatted with two digits (from `<<00>>' to `<<60>>'). The value 60 accounts for the occasional leap second. [tm_sec] @@ -1109,6 +1113,74 @@ recurse: tim_p->tm_hour, tim_p->tm_min); CHECK_LENGTH (); break; + case CQ('s'): +/* + * From: + * The Open Group Base Specifications Issue 7 + * IEEE Std 1003.1, 2013 Edition + * Copyright (c) 2001-2013 The IEEE and The Open Group + * XBD Base Definitions + * 4. General Concepts + * 4.15 Seconds Since the Epoch + * A value that approximates the number of seconds that have elapsed since the + * Epoch. A Coordinated Universal Time name (specified in terms of seconds + * (tm_sec), minutes (tm_min), hours (tm_hour), days since January 1 of the year + * (tm_yday), and calendar year minus 1900 (tm_year)) is related to a time + * represented as seconds since the Epoch, according to the expression below. + * If the year is <1970 or the value is negative, the relationship is undefined. + * If the year is >=1970 and the value is non-negative, the value is related to a + * Coordinated Universal Time name according to the C-language expression, where + * tm_sec, tm_min, tm_hour, tm_yday, and tm_year are all integer types: + * tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 + + * (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 - + * ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 + * OR + * tm_year-69)/4 - (tm_year-1)/100 + (tm_year+299)/400 + + * (tm_year-70)*365 + tm_yday)*24 + tm_hour)*60 + tm_min)*60 + tm_sec + */ +/* modified from %z case by hoisting offset outside if block and initializing */ + { + long offset;/* offset < 0 => W of GMT, > 0 => E of GMT: + offset = 0;subtract to get UTC */ + + if (tim_p->tm_isdst >= 0) + { + TZ_LOCK; + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } + +#if defined (__CYGWIN__) + /* Cygwin must check if the application has been built with or + without the extra tm members for backward compatibility, and + then use either that or the old method fetching from tzinfo. + Rather than pulling in the version check infrastructure, we + jus
Re: Bash unable to print epoch timestamp
Forwarded Message Subject: Fwd: Re: Bash unable to print epoch timestamp Date: Fri, 23 Oct 2015 14:32:44 -0600 From: Brian Inglis <brian.ing...@systematicsw.ab.ca> Reply-To: brian.ing...@systematicsw.ab.ca Organisation: Systematic Software To: corinna-cyg...@cygwin.com Already forwarded as below to cygwin and ...patches-allow... - should be HTML free and pass filters? On 2015-10-26 11:34, Brian Inglis wrote: Third time lucky - pasting inline into email and resending to all previous lists. Please note that conversion into too-small buffer size in regression test may not have expected result! Tried to build with below and variants: gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf -I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o strftime-s-test strftime.c gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, __get_current_time_locale, __tz_lock, __tz_unlock, _tzset_unlocked Build stc with std cmdline and current strftime works and does demo issue. Sorry - redo with the file existing! -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada - >8 - 8< - /* newlib/libc/time/strftime.c %s format STC */ #include #include int main( int argc, char **argv) { char ss[BUFSIZ] = ""; time_t tt = time( NULL ); struct tm *tp = gmtime( ); tt = mktime( tp ); size_t st = strftime( ss, sizeof ss, "%s", tp); int rc = puts( ss ); st = strftime( ss, sizeof ss, "%T", tp); rc = puts( ss ); return rc; } - >8 - 8< - --- a/newlib/ChangeLog 2015-08-20 03:39:23.0 -0600 +++ b/newlib/ChangeLog 2015-10-26 18:50:44.165368900 -0600 @@ -1,3 +1,8 @@ +2015-10-12 Brian Inglis <brian.ing...@systematicsw.ab.ca> + + * libc/time/strftime.c (__strftime): add support for %s (seconds from + Unix epoch) + 2015-08-07 Stefan Wallentowitz <stefan.wallentow...@tum.de> * libc/sys/or1k/mlock.c: Fix exception enable saving --- a/newlib/libc/time/strftime.c 2015-08-20 03:39:24.0 -0600 +++ b/newlib/libc/time/strftime.c 2015-10-26 04:27:12.244016200 -0600 @@ -166,6 +166,10 @@ notations, the result is an empty string o %R The 24-hour time, to the minute. Equivalent to "%H:%M". [tm_min, tm_hour] +o %s +The time elapsed, in seconds, since the start of the Unix epoch at +1970-01-01 00:00:00 UTC. + o %S The second, formatted with two digits (from `<<00>>' to `<<60>>'). The value 60 accounts for the occasional leap second. [tm_sec] @@ -1109,6 +1113,74 @@ recurse: tim_p->tm_hour, tim_p->tm_min); CHECK_LENGTH (); break; + case CQ('s'): +/* + * From: + * The Open Group Base Specifications Issue 7 + * IEEE Std 1003.1, 2013 Edition + * Copyright (c) 2001-2013 The IEEE and The Open Group + * XBD Base Definitions + * 4. General Concepts + * 4.15 Seconds Since the Epoch + * A value that approximates the number of seconds that have elapsed since the + * Epoch. A Coordinated Universal Time name (specified in terms of seconds + * (tm_sec), minutes (tm_min), hours (tm_hour), days since January 1 of the year + * (tm_yday), and calendar year minus 1900 (tm_year)) is related to a time + * represented as seconds since the Epoch, according to the expression below. + * If the year is <1970 or the value is negative, the relationship is undefined. + * If the year is >=1970 and the value is non-negative, the value is related to a + * Coordinated Universal Time name according to the C-language expression, where + * tm_sec, tm_min, tm_hour, tm_yday, and tm_year are all integer types: + * tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 + + * (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 - + * ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 + * OR + * tm_year-69)/4 - (tm_year-1)/100 + (tm_year+299)/400 + + * (tm_year-70)*365 + tm_yday)*24 + tm_hour)*60 + tm_min)*60 + tm_sec + */ +/* modified from %z case by hoisting offset outside if block and initializing */ + { + long offset;/* offset < 0 => W of GMT, > 0 => E of GMT: + offset = 0;subtract to get UTC */ + + if (tim_p->tm_isdst >= 0) + { + TZ_LOCK; + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } + +#if defined (__CYGWIN__) + /* Cygwin must check if the application has been built with or + without the extra tm members for backward compatibility, and + then use either that or the old method fetching from tzinfo. + Rather than pulling in the version check infrastructure, we + jus
Re: Bash unable to print epoch timestamp
Third time lucky - pasting inline into email and resending to all previous lists. Please note that conversion into too-small buffer size in regression test may not have expected result! Tried to build with below and variants: gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf -I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o strftime-s-test strftime.c gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, __get_current_time_locale, __tz_lock, __tz_unlock, _tzset_unlocked Build stc with std cmdline and current strftime works and does demo issue. Forwarded Message Subject: Fwd: Re: Bash unable to print epoch timestamp Date: Fri, 23 Oct 2015 14:32:44 -0600 From: Brian Inglis <brian.ing...@systematicsw.ab.ca> Reply-To: brian.ing...@systematicsw.ab.ca Organisation: Systematic Software To: corinna-cyg...@cygwin.com Already forwarded as below to cygwin and ...patches-allow... - should be HTML free and pass filters? -- Take care. Thanks, Brian Inglis Forwarded Message Subject: Re: Bash unable to print epoch timestamp Date: Thu, 22 Oct 2015 18:08:52 -0600 From: Brian Inglis <brian.ing...@systematicsw.ab.ca> Reply-To: brian.ing...@systematicsw.ab.ca Organisation: Systematic Software To: cygwin@cygwin.com, cygwin-patches-allow-subscr...@cygwin.com Corinna Vinschen cygwin.com> wrote: On Oct 22 07:03, Brian Inglis wrote: Brian Inglis SystematicSw.ab.ca> writes: > Don Harrop effx.us> writes: > > Bash outputs no value when using it's built in method of printing an > > "epoch" timestamp. > > BashCommandLine#: printf '%(%s)T' -1 > bash printf depends on underlying strftime in newlib, which does not support > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that > is presumably not defined in the config, as %s is not shown in man strftime. > Workaround for now is use > date +%s > for current time, and > date -d $(printf '%(%T)T' -2) +%s > for shell invocation time. > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that Wrong! Misread the code, strftime %s is not supported! STC and suggested patch appended (posting from gmane), compiles, but can't build STC as ld fails with undef refs, and I don't know all the correct LD..., -L and -l incantations. Email me for original files. Cool, thanks for the patch. Unfortunately it doesn't apply cleanly. There are several unexpected line wraps and there's this: --- a/newlib/time/strftime.c 2015-08-20 03:39:24.0 -0600 +++ b/newlib/time/strftime.c 2015-10-21 20:15:22.367453000 -0600 How did this happen? If you checkout the newlib-cygwin git repo, strftime.c is under newlib/libc/time, not under newlib/time :o Tried to download and build from source tarball, then cygport, then local source file, but some unobvious build prereqs missing in all cases, as reported by ld. Finally just diffed local source against distro and posted from gmane, with attempted fixups in the post. Would you mind to attach a patch generated with git format-patch? Sorry, not using git yet, as I am set up with hg on BitBucket - AIUI the output is close enough the attached should work okay. [cc ...patches-allow...] -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada - >8 - 8< - /* newlib/libc/time/strftime.c %s format STC */ #include #include int main( int argc, char **argv) { char ss[BUFSIZ] = ""; time_t tt = time( NULL ); struct tm *tp = gmtime( ); tt = mktime( tp ); size_t st = strftime( ss, sizeof ss, "%s", tp); int rc = puts( ss ); st = strftime( ss, sizeof ss, "%T", tp); rc = puts( ss ); return rc; } - >8 - 8< - 2015-10-12 Brian Inglis <brian.ing...@systematicsw.ab.ca> * newlib/libc/time/strftime.c (__strftime): add support for %s (seconds from Unix epoch) --- a/newlib/libc/time/strftime.c 1969-12-31 17:00:00.0 -0700 +++ b/newlib/libc/time/strftime.c 2015-10-26 04:27:12.244016200 -0600 @@ -0,0 +1,1903 @@ +/* NOTE: This file defines both strftime() and wcsftime(). Take care when + * making changes. See also wcsftime.c, and note the (small) overlap in the + * manual description, taking care to edit both as needed. */ +/* + * strftime.c + * Original Author:G. Haley + * Additions from: Eric Blake + * Changes to allow dual use as wcstime, also: Craig Howland + * + * 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 + * the terminating null character is not more than maxsize, returns the number + * of characters placed into the array pointed to by s (not including the + * terminating null character); otherwise ze
Re: Bash unable to print epoch timestamp
Third time lucky - pasting inline into email and resending to all previous lists. Please note that conversion into too-small buffer size in regression test may not have expected result! Tried to build with below and variants: gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf -I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o strftime-s-test strftime.c gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, __get_current_time_locale, __tz_lock, __tz_unlock, _tzset_unlocked Build stc with std cmdline and current strftime works and does demo issue. Forwarded Message Subject: Fwd: Re: Bash unable to print epoch timestamp Date: Fri, 23 Oct 2015 14:32:44 -0600 From: Brian Inglis <brian.ing...@systematicsw.ab.ca> Reply-To: brian.ing...@systematicsw.ab.ca Organisation: Systematic Software To: corinna-cyg...@cygwin.com Already forwarded as below to cygwin and ...patches-allow... - should be HTML free and pass filters? -- Take care. Thanks, Brian Inglis Forwarded Message Subject: Re: Bash unable to print epoch timestamp Date: Thu, 22 Oct 2015 18:08:52 -0600 From: Brian Inglis <brian.ing...@systematicsw.ab.ca> Reply-To: brian.ing...@systematicsw.ab.ca Organisation: Systematic Software To: cyg...@cygwin.com, cygwin-patches-allow-subscr...@cygwin.com Corinna Vinschen cygwin.com> wrote: On Oct 22 07:03, Brian Inglis wrote: Brian Inglis SystematicSw.ab.ca> writes: > Don Harrop effx.us> writes: > > Bash outputs no value when using it's built in method of printing an > > "epoch" timestamp. > > BashCommandLine#: printf '%(%s)T' -1 > bash printf depends on underlying strftime in newlib, which does not support > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that > is presumably not defined in the config, as %s is not shown in man strftime. > Workaround for now is use > date +%s > for current time, and > date -d $(printf '%(%T)T' -2) +%s > for shell invocation time. > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that Wrong! Misread the code, strftime %s is not supported! STC and suggested patch appended (posting from gmane), compiles, but can't build STC as ld fails with undef refs, and I don't know all the correct LD..., -L and -l incantations. Email me for original files. Cool, thanks for the patch. Unfortunately it doesn't apply cleanly. There are several unexpected line wraps and there's this: --- a/newlib/time/strftime.c 2015-08-20 03:39:24.0 -0600 +++ b/newlib/time/strftime.c 2015-10-21 20:15:22.367453000 -0600 How did this happen? If you checkout the newlib-cygwin git repo, strftime.c is under newlib/libc/time, not under newlib/time :o Tried to download and build from source tarball, then cygport, then local source file, but some unobvious build prereqs missing in all cases, as reported by ld. Finally just diffed local source against distro and posted from gmane, with attempted fixups in the post. Would you mind to attach a patch generated with git format-patch? Sorry, not using git yet, as I am set up with hg on BitBucket - AIUI the output is close enough the attached should work okay. [cc ...patches-allow...] -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada - >8 - 8< - /* newlib/libc/time/strftime.c %s format STC */ #include #include int main( int argc, char **argv) { char ss[BUFSIZ] = ""; time_t tt = time( NULL ); struct tm *tp = gmtime( ); tt = mktime( tp ); size_t st = strftime( ss, sizeof ss, "%s", tp); int rc = puts( ss ); st = strftime( ss, sizeof ss, "%T", tp); rc = puts( ss ); return rc; } - >8 - 8< - 2015-10-12 Brian Inglis <brian.ing...@systematicsw.ab.ca> * newlib/libc/time/strftime.c (__strftime): add support for %s (seconds from Unix epoch) --- a/newlib/libc/time/strftime.c 1969-12-31 17:00:00.0 -0700 +++ b/newlib/libc/time/strftime.c 2015-10-26 04:27:12.244016200 -0600 @@ -0,0 +1,1903 @@ +/* NOTE: This file defines both strftime() and wcsftime(). Take care when + * making changes. See also wcsftime.c, and note the (small) overlap in the + * manual description, taking care to edit both as needed. */ +/* + * strftime.c + * Original Author:G. Haley + * Additions from: Eric Blake + * Changes to allow dual use as wcstime, also: Craig Howland + * + * 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 + * the terminating null character is not more than maxsize, returns the number + * of characters placed into the array pointed to by s (not including the + * terminating null character); otherwise ze
Re: Bash unable to print epoch timestamp
Corinna Vinschen writes: > > Brian, ping? Hi Corinna, Just sent third try to this list, -patches, and yourself: May have been blocked because thunderbird decided to base64 encode the stc attachment ("smart" attachments?) whereas the patch was inlined properly! Note in latest attempt: "Third time lucky - pasting inline into email and resending to all previous lists. Please note that conversion into too-small buffer size in regression test may not have expected result! Tried to build with below and variants: gcc -D_REGRESSION_TEST -D_COMPILING_NEWLIB -Dsniprintf=snprintf -I/usr/src/cygwin-2.2.1-1.src/newlib-cygwin/winsup/cygwin/include -o strftime-s-test strftime.c gives undef refs for __cygwin_gettzname, __cygwin_gettzoffset, __get_current_time_locale, __tz_lock, __tz_unlock, _tzset_unlocked Build stc with std cmdline and current strftime works and does demo issue." -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Re: Bash unable to print epoch timestamp
Hi Brian, On Oct 22 07:03, Brian Inglis wrote: > Brian Inglis SystematicSw.ab.ca> writes: > > > > > Don Harrop effx.us> writes: > > > Bash outputs no value when using it's built in method of printing an > > > "epoch" timestamp. > > > BashCommandLine#: printf '%(%s)T' -1 > > > > bash printf depends on underlying strftime in newlib, which does not support > > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that > > is presumably not defined in the config, as %s is not shown in man > > strftime. > > Workaround for now is use > > date +%s > > for current time, and > >date -d $(printf '%(%T)T' -2) +%s > > for shell invocation time. > > > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that > Wrong! Misread the code, strftime %s is not supported! > > STC and suggested patch appended (posting from gmane), compiles, but can't > build STC as ld fails with undef refs, and I don't know all the correct > LD..., -L and -l incantations. Email me for original files. Cool, thanks for the patch. Unfortunately it doesn't apply cleanly. There are several unexpected line wraps and there's this: > --- a/newlib/time/strftime.c2015-08-20 03:39:24.0 -0600 > +++ b/newlib/time/strftime.c2015-10-21 20:15:22.367453000 -0600 How did this happen? If you checkout the newlib-cygwin git repo, strftime.c is under newlib/libc/time, not under newlib/time :o Would you mind to attach a patch generated with git format-patch? Thanks in advance, Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat pgpDADcG5qWZg.pgp Description: PGP signature
Re: Bash unable to print epoch timestamp
Brian Inglis SystematicSw.ab.ca> writes: > > Don Harrop effx.us> writes: > > Bash outputs no value when using it's built in method of printing an > > "epoch" timestamp. > > BashCommandLine#: printf '%(%s)T' -1 > > bash printf depends on underlying strftime in newlib, which does not support > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that > is presumably not defined in the config, as %s is not shown in man strftime. > Workaround for now is use > date +%s > for current time, and >date -d $(printf '%(%T)T' -2) +%s > for shell invocation time. > %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that Wrong! Misread the code, strftime %s is not supported! STC and suggested patch appended (posting from gmane), compiles, but can't build STC as ld fails with undef refs, and I don't know all the correct LD..., -L and -l incantations. Email me for original files. /* newlib/time/strftime.c %s format STC */ #include #include int main( int argc, char **argv) { char ss[BUFSIZ] = ""; time_t tt = time( NULL ); struct tm *tp = gmtime( ); tt = mktime( tp ); size_t st = strftime( ss, sizeof ss, "%s", tp); int rc = puts( ss ); st = strftime( ss, sizeof ss, "%T", tp); rc = puts( ss ); return rc; } --- 8< --- 2015-10-12 Brian Inglis* newlib/time/strftime.c (__strftime): add support for %s (seconds from Unix epoch) --- a/newlib/time/strftime.c2015-08-20 03:39:24.0 -0600 +++ b/newlib/time/strftime.c2015-10-21 20:15:22.367453000 -0600 @@ -166,6 +166,10 @@ notations, the result is an empty string o %R The 24-hour time, to the minute. Equivalent to "%H:%M". [tm_min, tm_hour] +o %s +The time elapsed, in seconds, since the start of the Unix epoch at +1970-01-01 00:00:00 UTC. + o %S The second, formatted with two digits (from `<<00>>' to `<<60>>'). The value 60 accounts for the occasional leap second. [tm_sec] @@ -1109,6 +1113,74 @@ recurse: tim_p->tm_hour, tim_p->tm_min); CHECK_LENGTH (); break; + case CQ('s'): +/* + * From: + * The Open Group Base Specifications Issue 7 + * IEEE Std 1003.1, 2013 Edition + * Copyright (c) 2001-2013 The IEEE and The Open Group + * XBD Base Definitions + * 4. General Concepts + * 4.15 Seconds Since the Epoch + * A value that approximates the number of seconds that have elapsed since the + * Epoch. A Coordinated Universal Time name (specified in terms of seconds + * (tm_sec), minutes (tm_min), hours (tm_hour), days since January 1 of the year + * (tm_yday), and calendar year minus 1900 (tm_year)) is related to a time + * represented as seconds since the Epoch, according to the expression below. + * If the year is <1970 or the value is negative, the relationship is undefined. + * If the year is >=1970 and the value is non-negative, the value is related to a + * Coordinated Universal Time name according to the C-language expression, where + * tm_sec, tm_min, tm_hour, tm_yday, and tm_year are all integer types: + * tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 + + * (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 - + * ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 + * OR + * tm_year-69)/4 - (tm_year-1)/100 + (tm_year+299)/400 + + * (tm_year-70)*365 + tm_yday)*24 + tm_hour)*60 + tm_min)*60 + tm_sec + */ +/* modified from %z case by hoisting offset outside if block and initializing */ + { + long offset;/* offset < 0 => W of GMT, > 0 => E of GMT: + offset = 0;subtract to get UTC */ + + if (tim_p->tm_isdst >= 0) + { + TZ_LOCK; + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } + +#if defined (__CYGWIN__) + /* Cygwin must check if the application has been built with or + without the extra tm members for backward compatibility, and + then use either that or the old method fetching from tzinfo. + Rather than pulling in the version check infrastructure, we + just call a Cygwin function. */ + extern long __cygwin_gettzoffset (const struct tm *tmp); + offset = __cygwin_gettzoffset (tim_p); +#elif defined (__TM_GMTOFF) + offset = tim_p->__TM_GMTOFF; +#else + __tzinfo_type *tz = __gettzinfo (); + /* 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; +#endif + TZ_UNLOCK; + } + len = snprintf
Re: Bash unable to print epoch timestamp
Don Harrop effx.us> writes: > Bash outputs no value when using it's built in method of printing an > "epoch" timestamp. > BashCommandLine#: printf '%(%s)T' -1 bash printf depends on underlying strftime in newlib, which does not support %s, as it is conditional on _WANT_C99_TIME_FORMATS being defined, and that is presumably not defined in the config, as %s is not shown in man strftime. Workaround for now is use date +%s for current time, and date -d $(printf '%(%T)T' -2) +%s for shell invocation time. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple