This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, libfortran] PR 47802 Implementation of CTIME intrinsic


Janne Blomqvist wrote:
> The attached patch changes the implementation of CTIME and FDATE to
> use strftime instead.

Thanks for the patch!

> A caveat is that as strftime supports i18n, if
> the program sets the LC_ALL/LC_TIME locale the output will not be the
> same as with ctime(). However, few if any Fortran programs call
> setlocale(), and for those that do, a localized time and date string
> might even be seen as a feature.
>
> Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

(I think one should deal with HP-UX's _REENTRANT issue as follow up,
cf. PR 47802, comment 17 and 18.)


I was wondering whether there are platforms which do not have
HAVE_STRFTIME. And if so, whether one shouldn't continue to fall
back to "ctime" in that case.



 fdate_sub (char * date, gfc_charlen_type date_len)
[...]
+  fctime (date, date_len, &now);

As convenient as I find that one directly passes the buffer:
Doesn't this reduce the number of characters effectively
by one? Assume 'Sat Aug 19 18:13:14 1995'. That's 24 characters.
If one now does:
  character(len=24) :: str
  call fdate(str)
will this work? I fear that this will produce
'Sat Aug 19 18:13:14 199\0'. It seems to work is the string is
at least one character longer than needed as then memset should
get rid of the tailing '\0'.


+   not available, gmtime use thread-local storage so it's

s/use/uses/



libgfortran/intrinsics/time_1.h
+static struct tm *
+localtime_r (const time_t * timep, struct tm * result)
+{
+  *result = *localtime (timep);
+  return result;
+}

Any reason that you do not mark it as inline?


Additionally, I would like to see the following documentation
changes, partially unrelated to your patch:
http://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
http://gcc.gnu.org/onlinedocs/gfortran/CTIME.html

- CTIME/FDATE: Mention as a note hat the string might be
  localized if setlocale had been called.

- CTIME: Document that TIME also accepts INTEGER(4)
  (Actually, it internally only accepts integer(8),
   but integer(4) is converted by the FE.)
- CTIME: Cross reference to DATE_AND_TIME and FDATE
- FDATA: Cross reference to DATE_AND_TIME and CTIME

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]