Contents of /trunk/mkinitrd-magellan/busybox/libbb/compare_string_array.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 822 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 822 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
4 | */ |
5 | |
6 | #include "libbb.h" |
7 | |
8 | /* returns the array index of the string */ |
9 | /* (index of first match is returned, or -1) */ |
10 | int index_in_str_array(const char * const string_array[], const char *key) |
11 | { |
12 | int i; |
13 | |
14 | for (i = 0; string_array[i] != 0; i++) { |
15 | if (strcmp(string_array[i], key) == 0) { |
16 | return i; |
17 | } |
18 | } |
19 | return -1; |
20 | } |
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 | } |