aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/time.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-29 11:48:06 +0800
committerGitHub <noreply@github.com>2022-11-29 11:48:06 +0800
commit98695b49992daa2b40eb3d5b5e4a86e99c92ed0e (patch)
treee461078a5a2edb2ff897744bf1be4fc3f90c6ed2 /src/nvim/os/time.c
parent7328c4de54ac96b39853b3f43736aff863fd209d (diff)
downloadrneovim-98695b49992daa2b40eb3d5b5e4a86e99c92ed0e.tar.gz
rneovim-98695b49992daa2b40eb3d5b5e4a86e99c92ed0e.tar.bz2
rneovim-98695b49992daa2b40eb3d5b5e4a86e99c92ed0e.zip
vim-patch:8.1.1313: warnings for using localtime() and ctime() (#21229)
Problem: Warnings for using localtime() and ctime(). Solution: Use localtime_r() if available. Avoid using ctime(). https://github.com/vim/vim/commit/63d2555c9cefbbeeca3ec87fdd5d241e9488f9dd Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/os/time.c')
-rw-r--r--src/nvim/os/time.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index 360565fbc5..873302a27d 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -179,7 +179,8 @@ struct tm *os_localtime(struct tm *result) FUNC_ATTR_NONNULL_ALL
/// @param result[out] Pointer to a 'char' where the result should be placed
/// @param result_len length of result buffer
/// @return human-readable string of current local time
-char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t result_len)
+char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t result_len,
+ bool add_newline)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{
struct tm clock_local;
@@ -197,7 +198,9 @@ char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t res
xstrlcpy(result, _("(Invalid)"), result_len - 1);
}
}
- xstrlcat(result, "\n", result_len);
+ if (add_newline) {
+ xstrlcat(result, "\n", result_len);
+ }
return result;
}
@@ -206,11 +209,11 @@ char *os_ctime_r(const time_t *restrict clock, char *restrict result, size_t res
/// @param result[out] Pointer to a 'char' where the result should be placed
/// @param result_len length of result buffer
/// @return human-readable string of current local time
-char *os_ctime(char *result, size_t result_len)
+char *os_ctime(char *result, size_t result_len, bool add_newline)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{
time_t rawtime = time(NULL);
- return os_ctime_r(&rawtime, result, result_len);
+ return os_ctime_r(&rawtime, result, result_len, add_newline);
}
/// Portable version of POSIX strptime()