Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/compare_string_array.c

    r1765 r2725  
    11/* vi: set sw=4 ts=4: */
    22/*
    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 source tree.
    44 */
    55
     
    88/* returns the array index of the string */
    99/* (index of first match is returned, or -1) */
    10 int index_in_str_array(const char *const string_array[], const char *key)
     10int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key)
    1111{
    1212    int i;
     
    2020}
    2121
    22 int index_in_strings(const char *strings, const char *key)
     22int FAST_FUNC index_in_strings(const char *strings, const char *key)
    2323{
    2424    int idx = 0;
    2525
    26     while (strings[0]) {
     26    while (*strings) {
    2727        if (strcmp(strings, key) == 0) {
    2828            return idx;
     
    3737/* (index of first match is returned, or -1) */
    3838#ifdef UNUSED
    39 int index_in_substr_array(const char *const string_array[], const char *key)
     39int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
    4040{
    4141    int i;
     
    5252#endif
    5353
    54 int index_in_substrings(const char *strings, const char *key)
     54int FAST_FUNC index_in_substrings(const char *strings, const char *key)
    5555{
    56     int len = strlen(key);
     56    int matched_idx = -1;
     57    const int len = strlen(key);
    5758
    5859    if (len) {
    5960        int idx = 0;
    60         while (strings[0]) {
     61        while (*strings) {
    6162            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;
    6368            }
    6469            strings += strlen(strings) + 1; /* skip NUL */
     
    6671        }
    6772    }
    68     return -1;
     73    return matched_idx;
    6974}
     75
     76const char* FAST_FUNC nth_string(const char *strings, int n)
     77{
     78    while (n) {
     79        n--;
     80        strings += strlen(strings) + 1;
     81    }
     82    return strings;
     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.  */
     87smallint 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
Note: See TracChangeset for help on using the changeset viewer.