diff options
author | Tom Tromey <tom@tromey.com> | 2021-06-04 16:00:33 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-11-05 13:58:48 -0600 |
commit | be77dd73c769b3e7ac62bd4c0b98242b62d080e0 (patch) | |
tree | 42467dc2ff4b18810660886835c51503b6ffacb7 /gdbsupport/gdb_unique_ptr.h | |
parent | 8a89ddbda2ecb41be0f12142e5d4b95c7bd5a138 (diff) | |
download | gdb-be77dd73c769b3e7ac62bd4c0b98242b62d080e0.zip gdb-be77dd73c769b3e7ac62bd4c0b98242b62d080e0.tar.gz gdb-be77dd73c769b3e7ac62bd4c0b98242b62d080e0.tar.bz2 |
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.
Diffstat (limited to 'gdbsupport/gdb_unique_ptr.h')
-rw-r--r-- | gdbsupport/gdb_unique_ptr.h | 9 |
1 files changed, 9 insertions, 0 deletions
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<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 */ |