aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/memline.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-03-20 05:50:16 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-03-29 09:41:17 -0400
commit573671b1fbcbc43b622391f50f4df30594f14751 (patch)
treea83617d57514e5d9f21f84179981fe945a181ddc /src/nvim/memline.c
parente700a88bb6bdc96f4d62a384aecd3bec2040ac3b (diff)
downloadrneovim-573671b1fbcbc43b622391f50f4df30594f14751.tar.gz
rneovim-573671b1fbcbc43b622391f50f4df30594f14751.tar.bz2
rneovim-573671b1fbcbc43b622391f50f4df30594f14751.zip
vim-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(). https://github.com/vim/vim/commit/63d2555c9cefbbeeca3ec87fdd5d241e9488f9dd
Diffstat (limited to 'src/nvim/memline.c')
-rw-r--r--src/nvim/memline.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index fa7c39cc65..b695d0e139 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1504,16 +1504,15 @@ static time_t swapfile_info(char_u *fname)
int fd;
struct block0 b0;
time_t x = (time_t)0;
- char *p;
#ifdef UNIX
char uname[B0_UNAME_SIZE];
#endif
- /* print the swap file date */
+ // print the swap file date
FileInfo file_info;
if (os_fileinfo((char *)fname, &file_info)) {
#ifdef UNIX
- /* print name of owner of the file */
+ // print name of owner of the file
if (os_get_uname(file_info.stat.st_uid, uname, B0_UNAME_SIZE) == OK) {
MSG_PUTS(_(" owned by: "));
msg_outtrans((char_u *)uname);
@@ -1522,11 +1521,8 @@ static time_t swapfile_info(char_u *fname)
#endif
MSG_PUTS(_(" dated: "));
x = file_info.stat.st_mtim.tv_sec;
- p = ctime(&x); // includes '\n'
- if (p == NULL)
- MSG_PUTS("(invalid)\n");
- else
- MSG_PUTS(p);
+ char ctime_buf[50];
+ MSG_PUTS(os_ctime_r(&x, ctime_buf, sizeof(ctime_buf)));
}
/*
@@ -3267,15 +3263,13 @@ attention_message (
)
{
assert(buf->b_fname != NULL);
- time_t x, sx;
- char *p;
++no_wait_return;
(void)EMSG(_("E325: ATTENTION"));
MSG_PUTS(_("\nFound a swap file by the name \""));
msg_home_replace(fname);
MSG_PUTS("\"\n");
- sx = swapfile_info(fname);
+ const time_t swap_mtime = swapfile_info(fname);
MSG_PUTS(_("While opening file \""));
msg_outtrans(buf->b_fname);
MSG_PUTS("\"\n");
@@ -3284,14 +3278,12 @@ attention_message (
MSG_PUTS(_(" CANNOT BE FOUND"));
} else {
MSG_PUTS(_(" dated: "));
- x = file_info.stat.st_mtim.tv_sec;
- p = ctime(&x); // includes '\n'
- if (p == NULL)
- MSG_PUTS("(invalid)\n");
- else
- MSG_PUTS(p);
- if (sx != 0 && x > sx)
+ time_t x = file_info.stat.st_mtim.tv_sec;
+ char ctime_buf[50];
+ MSG_PUTS(os_ctime_r(&x, ctime_buf, sizeof(ctime_buf)));
+ if (swap_mtime != 0 && x > swap_mtime) {
MSG_PUTS(_(" NEWER than swap file!\n"));
+ }
}
/* Some of these messages are long to allow translation to
* other languages. */