summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-04-08 00:03:39 +0200
committerMichael Adam <obnox@samba.org>2008-04-10 01:28:55 +0200
commit862608ca1fa0bcec100f23fff326a571df967235 (patch)
tree6ccc885ccb0e0bf05b7a766d9095fd9076ff600c
parent498e5f99d256dd1394d4fa3b3ea8cbf9ca51e109 (diff)
downloadsamba-862608ca1fa0bcec100f23fff326a571df967235.tar.gz
samba-862608ca1fa0bcec100f23fff326a571df967235.tar.bz2
samba-862608ca1fa0bcec100f23fff326a571df967235.zip
libsmbconf: add smbconf_reverse_find_in_array() to find last occurence of a string.
Michael (This used to be commit 25e0fd84780f4acb80cac3b5f54f9597e0e2f53e)
-rw-r--r--source3/lib/smbconf/smbconf_private.h3
-rw-r--r--source3/lib/smbconf/smbconf_util.c21
2 files changed, 24 insertions, 0 deletions
diff --git a/source3/lib/smbconf/smbconf_private.h b/source3/lib/smbconf/smbconf_private.h
index cba9148c7c..44229e26ec 100644
--- a/source3/lib/smbconf/smbconf_private.h
+++ b/source3/lib/smbconf/smbconf_private.h
@@ -70,4 +70,7 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
bool smbconf_find_in_array(const char *string, char **list,
uint32_t num_entries, uint32_t *entry);
+bool smbconf_reverse_find_in_array(const char *string, char **list,
+ uint32_t num_entries, uint32_t *entry);
+
#endif
diff --git a/source3/lib/smbconf/smbconf_util.c b/source3/lib/smbconf/smbconf_util.c
index 99b08cdd70..ee79b6360f 100644
--- a/source3/lib/smbconf/smbconf_util.c
+++ b/source3/lib/smbconf/smbconf_util.c
@@ -122,3 +122,24 @@ bool smbconf_find_in_array(const char *string, char **list,
return false;
}
+
+bool smbconf_reverse_find_in_array(const char *string, char **list,
+ uint32_t num_entries, uint32_t *entry)
+{
+ uint32_t i;
+
+ if ((string == NULL) || (list == NULL) || (num_entries == 0)) {
+ return false;
+ }
+
+ for (i = num_entries - 1; i >= 0; i++) {
+ if (strequal(string, list[i])) {
+ if (entry != NULL) {
+ *entry = i;
+ }
+ return true;
+ }
+ }
+
+ return false;
+}