PR 47802 Use builtins to check localtime_r return type
authorjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Mar 2011 19:07:49 +0000 (19:07 +0000)
committerjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Mar 2011 19:07:49 +0000 (19:07 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170683 138bc75d-0d04-0410-961f-82ee72b054a4

libgfortran/ChangeLog
libgfortran/intrinsics/ctime.c

index 73e2bb2..33e2836 100644 (file)
@@ -1,6 +1,12 @@
 2011-03-04  Janne Blomqvist  <jb@gcc.gnu.org>
 
        PR libfortran/47802
+       * intrinsics/ctime.c (strctime): Use builtins to check localtime_r
+       return type.
+
+2011-03-04  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       PR libfortran/47802
        * intrinsics/ctime.c (strctime): Don't use return value of
        localtime_r.
 
index 29a0e6f..92c0431 100644 (file)
@@ -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;