[pulseaudio-discuss] [PATCH 6/5] dynarray: Add pa_dynarray_last()
Tanu Kaskinen
tanu.kaskinen at linux.intel.com
Fri Jan 2 05:18:32 PST 2015
---
In addition to forgetting to add a cover letter to this patch series,
I also didn't include the first patch. Here's the missing patch.
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..743ac09 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 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