aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2011-03-04 21:07:49 +0200
committerJanne Blomqvist <jb@gcc.gnu.org>2011-03-04 21:07:49 +0200
commit246a2730176b7ad6bc24e9397cf41ccda733f460 (patch)
tree5c113b2f153cd7081f4f600fd26e915dce0b2c07 /libgfortran/intrinsics
parent87e7b310b3ddd203c446233d1517358e3708d9d7 (diff)
downloadgcc-246a2730176b7ad6bc24e9397cf41ccda733f460.zip
gcc-246a2730176b7ad6bc24e9397cf41ccda733f460.tar.gz
gcc-246a2730176b7ad6bc24e9397cf41ccda733f460.tar.bz2
PR 47802 Use builtins to check localtime_r return type
From-SVN: r170683
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r--libgfortran/intrinsics/ctime.c11
1 files changed, 8 insertions, 3 deletions
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, &ltm);
+ __builtin_choose_expr (__builtin_classify_type (localtime_r (timep, &ltm))
+ == 5,
+ failed = localtime_r (timep, &ltm) == NULL,
+ failed = localtime_r (timep, &ltm) != 0);
+ if (failed)
+ return 0;
return strftime (s, max, "%c", &ltm);
#else
return 0;