diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-05 18:05:09 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-05 18:05:09 +0000 |
commit | 5af906e7c834301a0f237b50e1a1474ce0cf6da0 (patch) | |
tree | 8a5a2783a458269715a05dc48236cae8b1cb1ee0 /libbb | |
parent | 402151671b58b264f9c023e8e29615b3dc3c9acc (diff) | |
download | busybox-w32-5af906e7c834301a0f237b50e1a1474ce0cf6da0.tar.gz busybox-w32-5af906e7c834301a0f237b50e1a1474ce0cf6da0.tar.bz2 busybox-w32-5af906e7c834301a0f237b50e1a1474ce0cf6da0.zip |
rename: compare_string_array -> index_in_str_array
introduce index_in_substr_array and use it in
iproute2
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/compare_string_array.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index cac93d995..d15578ca3 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c | |||
@@ -3,11 +3,11 @@ | |||
3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <string.h> | ||
7 | #include "libbb.h" | 6 | #include "libbb.h" |
8 | 7 | ||
9 | /* returns the array number of the string */ | 8 | /* returns the array index of the string */ |
10 | int compare_string_array(const char * const string_array[], const char *key) | 9 | /* (index of first match is returned, or -1) */ |
10 | int index_in_str_array(const char * const string_array[], const char *key) | ||
11 | { | 11 | { |
12 | int i; | 12 | int i; |
13 | 13 | ||
@@ -16,6 +16,22 @@ int compare_string_array(const char * const string_array[], const char *key) | |||
16 | return i; | 16 | return i; |
17 | } | 17 | } |
18 | } | 18 | } |
19 | return -i; | 19 | return -1; |
20 | } | 20 | } |
21 | 21 | ||
22 | /* returns the array index of the string, even if it matches only a beginning */ | ||
23 | /* (index of first match is returned, or -1) */ | ||
24 | int index_in_substr_array(const char * const string_array[], const char *key) | ||
25 | { | ||
26 | int i; | ||
27 | int len = strlen(key); | ||
28 | if (!len) | ||
29 | return -1; | ||
30 | |||
31 | for (i = 0; string_array[i] != 0; i++) { | ||
32 | if (strncmp(string_array[i], key, len) == 0) { | ||
33 | return i; | ||
34 | } | ||
35 | } | ||
36 | return -1; | ||
37 | } | ||