linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Tom Zanussi <zanussi@kernel.org>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-rt-users <linux-rt-users@vger.kernel.org>,
	Clark Williams <williams@redhat.com>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 5/9] libtracefs: Add API tracefs_list_dup()
Date: Tue, 10 Aug 2021 16:48:14 -0400	[thread overview]
Message-ID: <20210810204818.880714-6-rostedt@goodmis.org> (raw)
In-Reply-To: <20210810204818.880714-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add an API tracefs_list_dup() that will duplicate an existing list.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/tracefs.h   |  1 +
 src/tracefs-utils.c | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/tracefs.h b/include/tracefs.h
index f1e4ffa0d65f..6fb66c44afc7 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -67,6 +67,7 @@ void tracefs_list_free(char **list);
 char **tracefs_list_add(char **list, const char *string);
 int tracefs_list_size(char **list);
 int tracefs_list_pop(char **list);
+char **tracefs_list_dup(char **list);
 
 /**
  * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance
diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c
index 63bb413298fe..8c92d6c54ab1 100644
--- a/src/tracefs-utils.c
+++ b/src/tracefs-utils.c
@@ -489,3 +489,29 @@ int tracefs_list_size(char **list)
 	list--;
 	return (int)*(unsigned long *)list;
 }
+
+/**
+ * tracefs_list_dup - create a duplicate list
+ * @list: The list to duplicate
+ *
+ * Allocates a new list that can be modified and freed separately.
+ *
+ * Returns a new allocated list that must be freed with
+ * tracefs_list_free(), or NULL on error.
+ */
+char **tracefs_list_dup(char **list)
+{
+	char **new = NULL;
+	char **tmp;
+	int i;
+
+	for (i = 0; list[i]; i++) {
+		tmp = tracefs_list_add(new, list[i]);
+		if (!tmp) {
+			free(new);
+			return NULL;
+		}
+		new = tmp;
+	}
+	return new;
+}
-- 
2.30.2


  parent reply	other threads:[~2021-08-10 20:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 20:48 [PATCH 0/9] libtracefs: APIs to read a trace event hist file Steven Rostedt
2021-08-10 20:48 ` [PATCH 1/9] tracefs: Add API tracefs_hist_data_parse() Steven Rostedt
2021-09-10 16:54   ` Daniel Bristot de Oliveira
2021-08-10 20:48 ` [PATCH 2/9] libtracefs: Parse comment for hist data information Steven Rostedt
2021-08-10 20:48 ` [PATCH 3/9] libtracefs: Change hist_data_key type to flags Steven Rostedt
2021-08-10 20:48 ` [PATCH 4/9] libtracefs: Add API tracefs_hist_data_read() Steven Rostedt
2021-08-10 20:48 ` Steven Rostedt [this message]
2021-08-10 20:48 ` [PATCH 6/9] libtracefs: Add APIs tracefs_hist_data_keys/value_names() Steven Rostedt
2021-08-10 20:48 ` [PATCH 7/9] libtracefs: Add API tracefs_hist_data_keys/values() and next_bucket() Steven Rostedt
2021-08-10 20:48 ` [PATCH 8/9] libtracefs: Have tracefs_hist_bucket_key flags save the type Steven Rostedt
2021-08-10 20:48 ` [PATCH 9/9] libtracefs: Add man pages for tracefs_hist_data functions Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210810204818.880714-6-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=bristot@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=williams@redhat.com \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).