[DTrace-devel] [PATCH v2 14/20] Add dt_list_length()

Kris Van Hees kris.van.hees at oracle.com
Thu Jun 3 08:17:55 PDT 2021


Implement a function dt_list_length() to determine the number of
elements in a list.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_list.c | 14 +++++++++++++-
 libdtrace/dt_list.h |  3 ++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/libdtrace/dt_list.c b/libdtrace/dt_list.c
index 0f3855f9..32b5ea5c 100644
--- a/libdtrace/dt_list.c
+++ b/libdtrace/dt_list.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -88,3 +88,15 @@ dt_list_delete(dt_list_t *dlp, void *existing)
 	else
 		dlp->dl_prev = p->dl_prev;
 }
+
+size_t
+dt_list_length(dt_list_t *dlp)
+{
+	dt_list_t	*p;
+	size_t		len = 0;
+
+	for (p = dt_list_next(dlp); p != NULL; p = dt_list_next(p))
+		len++;
+
+	return len;
+}
diff --git a/libdtrace/dt_list.h b/libdtrace/dt_list.h
index 49b290f5..e6d4c863 100644
--- a/libdtrace/dt_list.h
+++ b/libdtrace/dt_list.h
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -26,6 +26,7 @@ extern void dt_list_append(dt_list_t *, void *);
 extern void dt_list_prepend(dt_list_t *, void *);
 extern void dt_list_insert(dt_list_t *, void *, void *);
 extern void dt_list_delete(dt_list_t *, void *);
+extern size_t dt_list_length(dt_list_t *);
 
 #ifdef	__cplusplus
 }
-- 
2.31.1




More information about the DTrace-devel mailing list