bionic: add __system_property_foreach

find_nth() will be inefficient on a trie.  Since find_nth() is only used
internally and only for enumerating properties, we can add a foreach()
function to do this directly.

Change-Id: I66bde9926c193073d74b244cce9fffd52108fff8
Signed-off-by: Greg Hackmann <ghackmann@google.com>
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp
index 60188f4..70ff1d6 100644
--- a/tests/system_properties_test.cpp
+++ b/tests/system_properties_test.cpp
@@ -125,6 +125,25 @@
     }
 }
 
+static void foreach_test_callback(const prop_info *pi, void* cookie) {
+    size_t *count = static_cast<size_t *>(cookie);
+
+    ASSERT_NE((prop_info *)NULL, pi);
+    (*count)++;
+}
+
+TEST(properties, foreach) {
+    LocalPropertyTestState pa;
+    size_t count = 0;
+
+    ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
+    ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
+    ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
+
+    ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count));
+    ASSERT_EQ(3U, count);
+}
+
 TEST(properties, find_nth) {
     LocalPropertyTestState pa;