[Bug libfortran/47802] [4.6 Regression] libgfortran/intrinsics/ctime.c:75:3: error: too few arguments to function 'ctime_r'

jb at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Feb 19 17:30:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47802

--- Comment #3 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-02-19 16:57:18 UTC ---
(In reply to comment #2)
> > Is there no way to get a posix compliant ctime?  Alternatively, we'll need
> > autoconf magic to detect the extra arg.  I know at one time it was relatively
> > common, so autoconf magic might be around somewhere.  Assuming it is you just
> > have to do something like
> > 
> > 
> > #if defined (oddballctime)
> >   *date = ctime_r (&now, cbuf, CSZ);
> > #else
> >   *date = ctime_r (&now, cbuf);
> > #endif
> 
> Using ctime_r is a bit of a can of worms.  The GNU autoconf manual recommends
> not using ctime_r unless the inputs are known to be within certain limits.

Well, since the usage here is for the Fortran intrinsics CTIME and FDATE which
are defined as interfaces to ctime(), unless you're volunteering to fix all the
Fortran code out there using these intrinsics, there's not much we can do.

gfortran at least makes sure to call ctime_r() with a buffer of >= 26 bytes
which is what POSIX requires. If some platform overflows this buffer, a bug
report to the platform libc maintainers seems to be the correct approach.

> It seems HP-UX and Solaris have both forms.

For Solaris we had some similar problems with _r() functions, yes. This was
solved by 

AC_USE_SYSTEM_EXTENSIONS

(from ../config/extensions.m4) which sets _POSIX_PTHREAD_SEMANTICS on Solaris,
which makes it expose the POSIX standard interfaces rather than some
pre-standard version.

>  In the HP-UX 11 case,
> which form is used at compilation time depends on _PTHREADS_DRAFT4:
> 
> #          ifndef _PTHREADS_DRAFT4
>              extern char *ctime_r(const __time_t *, char *);
> #          else /* _PTHREADS_DRAFT4 */
>          extern int ctime_r(const __time_t *, char *, int);
> #          endif /* _PTHREADS_DRAFT4 */

Yes, so HP-UX 11 seems to do the right thing by default. So the problem is
HP-UX 10, which only provides the 3-arg form and not the standard one, right?

> Potential autoconf test:
> 
> # ctime_r --
> #
> # There are two versions of ctime_r, one of which takes a buffer length as a
> # third argument, and one which only takes two arguments.  (There is also a
> # difference in return values, but we handle that in the code itself.)
> AC_CHECK_FUNCS(ctime_r)
> if test "$ac_cv_func_ctime_r" = "yes"; then
> AC_CACHE_CHECK([for 2 or 3 argument version of ctime_r], db_cv_ctime_r_3arg, [
> AC_TRY_LINK([
> #include <time.h>], [
>     ctime_r(NULL, NULL, 100);
> ],  [db_cv_ctime_r_3arg="3-argument"], [db_cv_ctime_r_3arg="2-argument"])])
> fi
> if test "$db_cv_ctime_r_3arg" = "3-argument"; then
>     AC_DEFINE(HAVE_CTIME_R_3ARG)
>     AH_TEMPLATE(HAVE_CTIME_R_3ARG,
>         [Define to 1 if ctime_r takes a buffer length as a third argument.])
> fi

Thanks, that looks like a doable approach. Unless somebody else gets there
first, I'll try to find some time to do this next week.



More information about the Gcc-bugs mailing list