From 862608ca1fa0bcec100f23fff326a571df967235 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 8 Apr 2008 00:03:39 +0200 Subject: libsmbconf: add smbconf_reverse_find_in_array() to find last occurence of a string. Michael (This used to be commit 25e0fd84780f4acb80cac3b5f54f9597e0e2f53e) --- source3/lib/smbconf/smbconf_private.h | 3 +++ source3/lib/smbconf/smbconf_util.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) 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; +} -- cgit