aboutsummaryrefslogtreecommitdiffstats
path: root/trace-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'trace-util.c')
-rw-r--r--trace-util.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/trace-util.c b/trace-util.c
index 058c9d2..33dbdf0 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -241,6 +241,19 @@ static char *append_file(const char *dir, const char *name)
241 return file; 241 return file;
242} 242}
243 243
244/**
245 * tracecmd_add_list - add an new string to a string list.
246 * @list: list to add the string to (may be NULL)
247 * @name: the string to add
248 * @len: current length of list of strings.
249 *
250 * The typical usage is:
251 *
252 * systems = tracecmd_add_list(systems, name, len++);
253 *
254 * Returns the new allocated list with an allocated name added.
255 * The list will end with NULL.
256 */
244char **tracecmd_add_list(char **list, const char *name, int len) 257char **tracecmd_add_list(char **list, const char *name, int len)
245{ 258{
246 if (!list) 259 if (!list)
@@ -260,6 +273,12 @@ char **tracecmd_add_list(char **list, const char *name, int len)
260 return list; 273 return list;
261} 274}
262 275
276/**
277 * tracecmd_free_list - free a list created with tracecmd_add_list.
278 * @list: The list to free.
279 *
280 * Frees the list as well as the names within the list.
281 */
263void tracecmd_free_list(char **list) 282void tracecmd_free_list(char **list)
264{ 283{
265 int i; 284 int i;
@@ -274,6 +293,37 @@ void tracecmd_free_list(char **list)
274} 293}
275 294
276/** 295/**
296 * tracecmd_add_id - add an int to the event id list
297 * @list: list to add the id to
298 * @id: id to add
299 * @len: current length of list of ids.
300 *
301 * The typical usage is:
302 *
303 * events = tracecmd_add_id(events, id, len++);
304 *
305 * Returns the new allocated list with the id included.
306 * the list will contain a '-1' at the end.
307 *
308 * The returned list should be freed with free().
309 */
310int *tracecmd_add_id(int *list, int id, int len)
311{
312 if (!list)
313 list = malloc_or_die(sizeof(*list) * 2);
314 else {
315 list = realloc(list, sizeof(*list) * (len + 2));
316 if (!list)
317 die("Can ont allocate list");
318 }
319
320 list[len++] = id;
321 list[len] = -1;
322
323 return list;
324}
325
326/**
277 * tracecmd_event_systems - return list of systems for tracing 327 * tracecmd_event_systems - return list of systems for tracing
278 * @tracing_dir: directory holding the "events" directory 328 * @tracing_dir: directory holding the "events" directory
279 * 329 *