[pulseaudio-discuss] [PATCH v2 1/6] dynarray: Add pa_dynarray_last()
Tanu Kaskinen
tanu.kaskinen at linux.intel.com
Wed Jan 7 06:56:47 PST 2015
---
src/pulsecore/dynarray.c | 9 +++++++++
src/pulsecore/dynarray.h | 3 +++
2 files changed, 12 insertions(+)
diff --git a/src/pulsecore/dynarray.c b/src/pulsecore/dynarray.c
index b207eca..82db496 100644
--- a/src/pulsecore/dynarray.c
+++ b/src/pulsecore/dynarray.c
@@ -79,6 +79,15 @@ void *pa_dynarray_get(pa_dynarray *array, unsigned i) {
return array->data[i];
}
+void *pa_dynarray_last(pa_dynarray *array) {
+ pa_assert(array);
+
+ if (array->n_entries == 0)
+ return NULL;
+
+ return array->data[array->n_entries - 1];
+}
+
void *pa_dynarray_steal_last(pa_dynarray *array) {
pa_assert(array);
diff --git a/src/pulsecore/dynarray.h b/src/pulsecore/dynarray.h
index 04dd2d2..946357b 100644
--- a/src/pulsecore/dynarray.h
+++ b/src/pulsecore/dynarray.h
@@ -50,6 +50,9 @@ void pa_dynarray_free(pa_dynarray *array);
void pa_dynarray_append(pa_dynarray *array, void *p);
void *pa_dynarray_get(pa_dynarray *array, unsigned i);
+/* Returns the last element, or NULL if the array is empty. */
+void *pa_dynarray_last(pa_dynarray *array);
+
/* Returns the removed item, or NULL if the array is empty. */
void *pa_dynarray_steal_last(pa_dynarray *array);
--
1.9.3
More information about the pulseaudio-discuss
mailing list