summaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-06 20:36:03 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-06 20:36:03 +0000
commite4ab123c32e6ee2064f01f5bb477bfaca438c20f (patch)
tree45c6c5ff8fa819ab554de69d49403a43f8de5ecb /libgfortran/intrinsics
parent692323c3112b3b579a1634758842ede7c416f94c (diff)
downloadgcc-e4ab123c32e6ee2064f01f5bb477bfaca438c20f.tar.gz
2011-03-06 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 170715 using svnmerge git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@170721 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r--libgfortran/intrinsics/ctime.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/libgfortran/intrinsics/ctime.c b/libgfortran/intrinsics/ctime.c
index 7eb10f5fa2c..92c0431357e 100644
--- a/libgfortran/intrinsics/ctime.c
+++ b/libgfortran/intrinsics/ctime.c
@@ -39,9 +39,18 @@ static size_t
strctime (char *s, size_t max, const time_t *timep)
{
#ifdef HAVE_STRFTIME
- struct tm res;
- struct tm *ltm = localtime_r (timep, &res);
- return strftime (s, max, "%c", ltm);
+ struct tm ltm;
+ 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*. */
+ __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;
#endif