diff options
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r-- | libgfortran/intrinsics/ctime.c | 15 |
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, <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; #endif |