Introduce make_unique_xstrndup

This adds a new make_unique_xstrndup function, which is the "n"
analogue of make_unique_xstrdup.  It also updates a couple existing
places to use this function.
This commit is contained in:
Tom Tromey
2021-06-04 16:00:33 -06:00
parent 8a89ddbda2
commit be77dd73c7
3 changed files with 14 additions and 5 deletions

View File

@ -64,4 +64,13 @@ make_unique_xstrdup (const char *str)
return gdb::unique_xmalloc_ptr<char> (xstrdup (str));
}
/* Dup the first N characters of STR and return a unique_xmalloc_ptr
for the result. The result is always \0-terminated. */
static inline gdb::unique_xmalloc_ptr<char>
make_unique_xstrndup (const char *str, size_t n)
{
return gdb::unique_xmalloc_ptr<char> (xstrndup (str, n));
}
#endif /* COMMON_GDB_UNIQUE_PTR_H */