From: Michael Adam Date: Mon, 7 Apr 2008 22:03:39 +0000 (+0200) Subject: libsmbconf: add smbconf_reverse_find_in_array() to find last occurence of a string. X-Git-Tag: samba-3.3.0pre1~2815 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25e0fd84780f4acb80cac3b5f54f9597e0e2f53e;p=thirdparty%2Fsamba.git libsmbconf: add smbconf_reverse_find_in_array() to find last occurence of a string. Michael --- diff --git a/source/lib/smbconf/smbconf_private.h b/source/lib/smbconf/smbconf_private.h index cba9148c7c8..44229e26ec3 100644 --- a/source/lib/smbconf/smbconf_private.h +++ b/source/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/source/lib/smbconf/smbconf_util.c b/source/lib/smbconf/smbconf_util.c index 99b08cdd708..ee79b6360fb 100644 --- a/source/lib/smbconf/smbconf_util.c +++ b/source/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; +}