From be77dd73c769b3e7ac62bd4c0b98242b62d080e0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 4 Jun 2021 16:00:33 -0600 Subject: 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. --- gdbsupport/gdb_unique_ptr.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gdbsupport') diff --git a/gdbsupport/gdb_unique_ptr.h b/gdbsupport/gdb_unique_ptr.h index df88cea..77aecb4 100644 --- a/gdbsupport/gdb_unique_ptr.h +++ b/gdbsupport/gdb_unique_ptr.h @@ -64,4 +64,13 @@ make_unique_xstrdup (const char *str) return gdb::unique_xmalloc_ptr (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 +make_unique_xstrndup (const char *str, size_t n) +{ + return gdb::unique_xmalloc_ptr (xstrndup (str, n)); +} + #endif /* COMMON_GDB_UNIQUE_PTR_H */ -- cgit v1.1