patch 8.1.1313: warnings for using localtime() and ctime()
Problem: Warnings for using localtime() and ctime().
Solution: Use localtime_r() if available. Avoid using ctime().
diff --git a/src/evalfunc.c b/src/evalfunc.c
index f3b1faf..ff51d12 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -13213,6 +13213,9 @@
f_strftime(typval_T *argvars, typval_T *rettv)
{
char_u result_buf[256];
+# ifdef HAVE_LOCALTIME_R
+ struct tm tmval;
+# endif
struct tm *curtime;
time_t seconds;
char_u *p;
@@ -13224,7 +13227,11 @@
seconds = time(NULL);
else
seconds = (time_t)tv_get_number(&argvars[1]);
+# ifdef HAVE_LOCALTIME_R
+ curtime = localtime_r(&seconds, &tmval);
+# else
curtime = localtime(&seconds);
+# endif
/* MSVC returns NULL for an invalid value of seconds. */
if (curtime == NULL)
rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)"));