POSIX specifies that st_mtime has type time_t, but some hosts declare
it with a different type, so its address cannot be passed to
localtime. Copy it to a time_t first.
Bootstrapped and regression-tested on x86_64-pc-linux-gnu
(default languages, --disable-multilib), with no new regressions
relative to the unmodified baseline.
Also tested with a non-GCC, EDG-based host compiler (GNU extensions
disabled) on a non-glibc platform, where the patch resolves a build
failure.
libcpp/ChangeLog:
* macro.cc (_cpp_builtin_macro_text) <BT_TIMESTAMP>: Copy st_mtime
to a time_t before calling localtime.
Signed-off-by: Shiva <[email protected]>
---
libcpp/macro.cc | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libcpp/macro.cc b/libcpp/macro.cc
index 736c360336d..f6f2dae55a5 100644
--- a/libcpp/macro.cc
+++ b/libcpp/macro.cc
@@ -593,7 +593,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode
*node,
struct tm *tb = NULL;
struct stat *st = _cpp_get_file_stat (file);
if (st)
- tb = localtime (&st->st_mtime);
+ {
+ time_t mtime = st->st_mtime;
+ tb = localtime (&mtime);
+ }
if (tb)
{
char *str = asctime (tb);