aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdb_obstack.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-07-13 12:13:15 -0600
committerTom Tromey <tom@tromey.com>2019-08-06 20:08:48 -0600
commit0cf9feb996cb32939840b13073a49310b1fd71e0 (patch)
tree4587051d5f873efbc2eacf85e23f2987f24d7571 /gdb/gdb_obstack.h
parentefba19b06a6f2baacb3920599f970d1333ffc358 (diff)
downloadgdb-0cf9feb996cb32939840b13073a49310b1fd71e0.zip
gdb-0cf9feb996cb32939840b13073a49310b1fd71e0.tar.gz
gdb-0cf9feb996cb32939840b13073a49310b1fd71e0.tar.bz2
Introduce obstack_strndup
This introduces obstack_strndup and changes gdb to use it. Note that obstack_strndup works like savestring, and not exactly like xstrndup. The difference is that obstack_strndup uses the passed-in length, while xstrndup uses strnlen to choose the length. gdb/ChangeLog 2019-08-06 Tom Tromey <tom@tromey.com> * stabsread.c (patch_block_stabs, read_one_struct_field) (read_enum_type): Use obstack_strndup. * rust-exp.y (rust_parser::copy_name): Use obstack_strndup. * gdb_obstack.h (obstack_strndup): Use obstack_strndup. * dwarf2read.c (guess_full_die_structure_name) (anonymous_struct_prefix): Use obstack_strndup. * dbxread.c (cp_set_block_scope): Use obstack_strndup. * c-exp.y (yylex): Use obstack_strndup. * ada-exp.y (write_object_renaming, write_ambiguous_var) (write_var_or_type): Use obstack_strndup.
Diffstat (limited to 'gdb/gdb_obstack.h')
-rw-r--r--gdb/gdb_obstack.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h
index db849a0..3d6a010 100644
--- a/gdb/gdb_obstack.h
+++ b/gdb/gdb_obstack.h
@@ -105,6 +105,17 @@ obstack_strdup (struct obstack *obstackp, const std::string &string)
string.size ());
}
+/* Duplicate the first N characters of STRING, returning a
+ \0-terminated string that's allocated on the obstack OBSTACKP.
+ Note that exactly N characters are copied, even if STRING is
+ shorter. */
+
+static inline char *
+obstack_strndup (struct obstack *obstackp, const char *string, size_t n)
+{
+ return (char *) obstack_copy0 (obstackp, string, n);
+}
+
/* An obstack that frees itself on scope exit. */
struct auto_obstack : obstack
{