From 246a2730176b7ad6bc24e9397cf41ccda733f460 Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Fri, 4 Mar 2011 21:07:49 +0200 Subject: PR 47802 Use builtins to check localtime_r return type From-SVN: r170683 --- libgfortran/intrinsics/ctime.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'libgfortran/intrinsics') diff --git a/libgfortran/intrinsics/ctime.c b/libgfortran/intrinsics/ctime.c index 29a0e6f..92c0431 100644 --- a/libgfortran/intrinsics/ctime.c +++ b/libgfortran/intrinsics/ctime.c @@ -40,11 +40,16 @@ strctime (char *s, size_t max, const time_t *timep) { #ifdef HAVE_STRFTIME struct tm ltm; - /* Note: We can't use the return value of localtime_r, as some - targets provide localtime_r based on a draft of the POSIX + int failed; + /* Some targets provide a localtime_r based on a draft of the POSIX standard where the return type is int rather than the standardized struct tm*. */ - localtime_r (timep, <m); + __builtin_choose_expr (__builtin_classify_type (localtime_r (timep, <m)) + == 5, + failed = localtime_r (timep, <m) == NULL, + failed = localtime_r (timep, <m) != 0); + if (failed) + return 0; return strftime (s, max, "%c", <m); #else return 0; -- cgit v1.1