diff options
Diffstat (limited to 'libgfortran/intrinsics/ctime.c')
-rw-r--r-- | libgfortran/intrinsics/ctime.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libgfortran/intrinsics/ctime.c b/libgfortran/intrinsics/ctime.c index 29a0e6f00f2..92c0431357e 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; |