From 88270a57358e4009537de9435c19fcb17e66ffdd Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 15 Apr 2022 19:49:06 +0200 Subject: refactor: add function xstrnsave xstrnsave is a clone of vim_strnsave that uses char* instead of char_u*. Its purpose short-term is to help reduce the number of casts and for long-term to replace vim_strnsave as the need to use char_u is eliminated. --- src/nvim/strings.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 9d4c64e4b1..848044ee7c 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -67,6 +67,13 @@ char_u *vim_strnsave(const char_u *string, size_t len) return (char_u *)strncpy(xmallocz(len), (char *)string, len); } +/// A clone of vim_strnsave() that uses char* instead of char_u* +char *xstrnsave(const char *string, size_t len) + FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL +{ + return strncpy(xmallocz(len), string, len); // NOLINT(runtime/printf) +} + /* * Same as vim_strsave(), but any characters found in esc_chars are preceded * by a backslash. -- cgit