mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 17:58:18 +00:00
memory: xstrchrnul and xmemscan.
This commit is contained in:
@@ -222,6 +222,35 @@ void *xmemdupz(const void *data, size_t len)
|
||||
return memcpy(xmallocz(len), data, len);
|
||||
}
|
||||
|
||||
/// A version of strchr() that returns a pointer to the terminating NUL if it
|
||||
/// doesn't find `c`.
|
||||
///
|
||||
/// @param str The string to search.
|
||||
/// @param c The char to look for.
|
||||
/// @returns a pointer to the first instance of `c`, or to the NUL terminator
|
||||
/// if not found.
|
||||
char *xstrchrnul(const char *str, char c)
|
||||
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
|
||||
{
|
||||
char *p = strchr(str, c);
|
||||
return p ? p : (char *)(str + strlen(str));
|
||||
}
|
||||
|
||||
/// A version of memchr() that returns a pointer one past the end
|
||||
/// if it doesn't find `c`.
|
||||
///
|
||||
/// @param addr The address of the memory object.
|
||||
/// @param c The char to look for.
|
||||
/// @param size The size of the memory object.
|
||||
/// @returns a pointer to the first instance of `c`, or one past the end if not
|
||||
/// found.
|
||||
void *xmemscan(const void *addr, char c, size_t size)
|
||||
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
|
||||
{
|
||||
char *p = memchr(addr, c, size);
|
||||
return p ? p : (char *)addr + size;
|
||||
}
|
||||
|
||||
/// The xstpcpy() function shall copy the string pointed to by src (including
|
||||
/// the terminating NUL character) into the array pointed to by dst.
|
||||
///
|
||||
|
Reference in New Issue
Block a user