diff options
-rw-r--r-- | libbb/compare_string_array.c | 23 | ||||
-rw-r--r-- | networking/brctl.c | 4 | ||||
-rw-r--r-- | networking/udhcp/common.c | 4 |
3 files changed, 24 insertions, 7 deletions
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index 43c59e8e0..599449fe0 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c | |||
@@ -53,19 +53,24 @@ int FAST_FUNC index_in_substr_array(const char *const string_array[], const char | |||
53 | 53 | ||
54 | int FAST_FUNC index_in_substrings(const char *strings, const char *key) | 54 | int FAST_FUNC index_in_substrings(const char *strings, const char *key) |
55 | { | 55 | { |
56 | int len = strlen(key); | 56 | int matched_idx = -1; |
57 | const int len = strlen(key); | ||
57 | 58 | ||
58 | if (len) { | 59 | if (len) { |
59 | int idx = 0; | 60 | int idx = 0; |
60 | while (*strings) { | 61 | while (*strings) { |
61 | if (strncmp(strings, key, len) == 0) { | 62 | if (strncmp(strings, key, len) == 0) { |
62 | return idx; | 63 | if (strings[len] == '\0') |
64 | return idx; /* exact match */ | ||
65 | if (matched_idx >= 0) | ||
66 | return -1; /* ambiguous match */ | ||
67 | matched_idx = idx; | ||
63 | } | 68 | } |
64 | strings += strlen(strings) + 1; /* skip NUL */ | 69 | strings += strlen(strings) + 1; /* skip NUL */ |
65 | idx++; | 70 | idx++; |
66 | } | 71 | } |
67 | } | 72 | } |
68 | return -1; | 73 | return matched_idx; |
69 | } | 74 | } |
70 | 75 | ||
71 | const char* FAST_FUNC nth_string(const char *strings, int n) | 76 | const char* FAST_FUNC nth_string(const char *strings, int n) |
@@ -76,3 +81,15 @@ const char* FAST_FUNC nth_string(const char *strings, int n) | |||
76 | } | 81 | } |
77 | return strings; | 82 | return strings; |
78 | } | 83 | } |
84 | |||
85 | #ifdef UNUSED_SO_FAR /* only brctl.c needs it yet */ | ||
86 | /* Returns 0 for no, 1 for yes or a negative value on error. */ | ||
87 | smallint FAST_FUNC yesno(const char *str) | ||
88 | { | ||
89 | static const char no_yes[] ALIGN1 = | ||
90 | "0\0" "off\0" "no\0" | ||
91 | "1\0" "on\0" "yes\0"; | ||
92 | int ret = index_in_substrings(no_yes, str); | ||
93 | return ret / 3; | ||
94 | } | ||
95 | #endif | ||
diff --git a/networking/brctl.c b/networking/brctl.c index 023518a26..a36ab45c3 100644 --- a/networking/brctl.c +++ b/networking/brctl.c | |||
@@ -220,10 +220,10 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) | |||
220 | } | 220 | } |
221 | #if ENABLE_FEATURE_BRCTL_FANCY | 221 | #if ENABLE_FEATURE_BRCTL_FANCY |
222 | if (key == ARG_stp) { /* stp */ | 222 | if (key == ARG_stp) { /* stp */ |
223 | static const char stp_opts[] ALIGN1 = | 223 | static const char no_yes[] ALIGN1 = |
224 | "0\0" "off\0" "n\0" "no\0" /* 0 .. 3 */ | 224 | "0\0" "off\0" "n\0" "no\0" /* 0 .. 3 */ |
225 | "1\0" "on\0" "y\0" "yes\0"; /* 4 .. 7 */ | 225 | "1\0" "on\0" "y\0" "yes\0"; /* 4 .. 7 */ |
226 | int onoff = index_in_strings(stp_opts, *argv); | 226 | int onoff = index_in_strings(no_yes, *argv); |
227 | if (onoff < 0) | 227 | if (onoff < 0) |
228 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); | 228 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); |
229 | onoff = (unsigned)onoff / 4; | 229 | onoff = (unsigned)onoff / 4; |
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 6e8ec3e64..adbcd77ac 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -435,8 +435,8 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | |||
435 | } | 435 | } |
436 | break; | 436 | break; |
437 | // case OPTION_BOOLEAN: { | 437 | // case OPTION_BOOLEAN: { |
438 | // static const char noyes[] ALIGN1 = "no\0yes\0"; | 438 | // static const char no_yes[] ALIGN1 = "no\0yes\0"; |
439 | // buffer[0] = retval = index_in_strings(noyes, val); | 439 | // buffer[0] = retval = index_in_strings(no_yes, val); |
440 | // retval++; /* 0 - bad; 1: "no" 2: "yes" */ | 440 | // retval++; /* 0 - bad; 1: "no" 2: "yes" */ |
441 | // break; | 441 | // break; |
442 | // } | 442 | // } |