diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2011-03-04 21:07:49 +0200 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2011-03-04 21:07:49 +0200 |
commit | 246a2730176b7ad6bc24e9397cf41ccda733f460 (patch) | |
tree | 5c113b2f153cd7081f4f600fd26e915dce0b2c07 /libgfortran | |
parent | 87e7b310b3ddd203c446233d1517358e3708d9d7 (diff) | |
download | gcc-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')
-rw-r--r-- | libgfortran/ChangeLog | 6 | ||||
-rw-r--r-- | libgfortran/intrinsics/ctime.c | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 73e2bb2..33e2836 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -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. 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, <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; |