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.
This commit is contained in:
Dundar Goc
2022-04-15 19:49:06 +02:00
parent 7a2fcbbbec
commit 88270a5735
4 changed files with 13 additions and 6 deletions

View File

@@ -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.