diff --git a/include/ChangeLog b/include/ChangeLog index f5be0c0154e..2acc42a0149 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2020-07-22 Nick Alcock + + * ctf-api.c (ctf_type_name_raw): New. + 2020-07-22 Nick Alcock * ctf-api.h (ECTF_*): Improve comments. diff --git a/include/ctf-api.h b/include/ctf-api.h index 2e3e28b840c..363b5c258ca 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -324,6 +324,7 @@ extern char *ctf_type_aname (ctf_file_t *, ctf_id_t); extern char *ctf_type_aname_raw (ctf_file_t *, ctf_id_t); extern ssize_t ctf_type_lname (ctf_file_t *, ctf_id_t, char *, size_t); extern char *ctf_type_name (ctf_file_t *, ctf_id_t, char *, size_t); +extern const char *ctf_type_name_raw (ctf_file_t *, ctf_id_t); extern ssize_t ctf_type_size (ctf_file_t *, ctf_id_t); extern ssize_t ctf_type_align (ctf_file_t *, ctf_id_t); extern int ctf_type_kind (ctf_file_t *, ctf_id_t); diff --git a/libctf/ChangeLog b/libctf/ChangeLog index 48798043efd..1754baf83db 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,8 @@ +2020-07-22 Nick Alcock + + * ctf-types.c (ctf_type_name_raw): New. + (ctf_type_aname_raw): Reimplement accordingly. + 2020-07-22 Nick Alcock * ctf-subr.c (ctf_dprintf): _libctf_debug is unlikely to be set. diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index db42b9e8a90..ce3890c33a6 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -472,19 +472,30 @@ ctf_type_name (ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) return (rv >= 0 && (size_t) rv < len ? buf : NULL); } -/* Lookup the given type ID and return its raw, unadorned, undecorated name as a - new dynamcally-allocated string. */ +/* Lookup the given type ID and return its raw, unadorned, undecorated name. + The name will live as long as its ctf_file_t does. */ -char * -ctf_type_aname_raw (ctf_file_t *fp, ctf_id_t type) +const char * +ctf_type_name_raw (ctf_file_t *fp, ctf_id_t type) { const ctf_type_t *tp; if ((tp = ctf_lookup_by_id (&fp, type)) == NULL) return NULL; /* errno is set for us. */ - if (ctf_strraw (fp, tp->ctt_name) != NULL) - return strdup (ctf_strraw (fp, tp->ctt_name)); + return ctf_strraw (fp, tp->ctt_name); +} + +/* Lookup the given type ID and return its raw, unadorned, undecorated name as a + new dynamically-allocated string. */ + +char * +ctf_type_aname_raw (ctf_file_t *fp, ctf_id_t type) +{ + const char *name = ctf_type_name_raw (fp, type); + + if (name != NULL) + return strdup (name); return NULL; } diff --git a/libctf/libctf.ver b/libctf/libctf.ver index aad304bc0d9..30a0b087bd6 100644 --- a/libctf/libctf.ver +++ b/libctf/libctf.ver @@ -57,6 +57,7 @@ LIBCTF_1.0 { ctf_type_resolve; ctf_type_lname; ctf_type_name; + ctf_type_name_raw; ctf_type_aname; ctf_type_aname_raw; ctf_type_size;