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/bb_strtonum.c

    r1765 r2725  
    55 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
    99
     
    1111
    1212/* On exit: errno = 0 only if there was non-empty, '\0' terminated value
    13  * errno = EINVAL if value was not '\0' terminated, but othervise ok
     13 * errno = EINVAL if value was not '\0' terminated, but otherwise ok
    1414 *    Return value is still valid, caller should just check whether end[0]
    1515 *    is a valid terminating char for particular case. OTOH, if caller
     
    1919 * errno = ERANGE if value had minus sign for strtouXX (even "-0" is not ok )
    2020 *    return value is all-ones in this case.
     21 *
     22 * Test code:
     23 * char *endptr;
     24 * const char *minus = "-";
     25 * errno = 0;
     26 * bb_strtoi(minus, &endptr, 0); // must set ERANGE
     27 * printf("minus:%p endptr:%p errno:%d EINVAL:%d\n", minus, endptr, errno, EINVAL);
     28 * errno = 0;
     29 * bb_strtoi("-0-", &endptr, 0); // must set EINVAL and point to second '-'
     30 * printf("endptr[0]:%c errno:%d EINVAL:%d\n", endptr[0], errno, EINVAL);
    2131 */
    2232
     
    3040{
    3141    if (endp) *endp = endptr;
    32 
    33     /* Check for the weird "feature":
    34      * a "-" string is apparently a valid "number" for strto[u]l[l]!
    35      * It returns zero and errno is 0! :( */
    36     if (endptr[-1] == '-')
    37         return ret_ERANGE();
    3842
    3943    /* errno is already set to ERANGE by strtoXXX if value overflowed */
     
    4953
    5054
    51 unsigned long long bb_strtoull(const char *arg, char **endp, int base)
     55unsigned long long FAST_FUNC bb_strtoull(const char *arg, char **endp, int base)
    5256{
    5357    unsigned long long v;
     
    6468}
    6569
    66 long long bb_strtoll(const char *arg, char **endp, int base)
     70long long FAST_FUNC bb_strtoll(const char *arg, char **endp, int base)
    6771{
    6872    unsigned long long v;
    6973    char *endptr;
    7074
    71     if (arg[0] != '-' && !isalnum(arg[0])) return ret_ERANGE();
     75    /* Check for the weird "feature":
     76     * a "-" string is apparently a valid "number" for strto[u]l[l]!
     77     * It returns zero and errno is 0! :( */
     78    char first = (arg[0] != '-' ? arg[0] : arg[1]);
     79    if (!isalnum(first)) return ret_ERANGE();
     80
    7281    errno = 0;
    7382    v = strtoll(arg, &endptr, base);
     
    7685
    7786#if ULONG_MAX != ULLONG_MAX
    78 unsigned long bb_strtoul(const char *arg, char **endp, int base)
     87unsigned long FAST_FUNC bb_strtoul(const char *arg, char **endp, int base)
    7988{
    8089    unsigned long v;
     
    8796}
    8897
    89 long bb_strtol(const char *arg, char **endp, int base)
     98long FAST_FUNC bb_strtol(const char *arg, char **endp, int base)
    9099{
    91100    long v;
    92101    char *endptr;
    93102
    94     if (arg[0] != '-' && !isalnum(arg[0])) return ret_ERANGE();
     103    char first = (arg[0] != '-' ? arg[0] : arg[1]);
     104    if (!isalnum(first)) return ret_ERANGE();
     105
    95106    errno = 0;
    96107    v = strtol(arg, &endptr, base);
     
    100111
    101112#if UINT_MAX != ULONG_MAX
    102 unsigned bb_strtou(const char *arg, char **endp, int base)
     113unsigned FAST_FUNC bb_strtou(const char *arg, char **endp, int base)
    103114{
    104115    unsigned long v;
     
    112123}
    113124
    114 int bb_strtoi(const char *arg, char **endp, int base)
     125int FAST_FUNC bb_strtoi(const char *arg, char **endp, int base)
    115126{
    116127    long v;
    117128    char *endptr;
    118129
    119     if (arg[0] != '-' && !isalnum(arg[0])) return ret_ERANGE();
     130    char first = (arg[0] != '-' ? arg[0] : arg[1]);
     131    if (!isalnum(first)) return ret_ERANGE();
     132
    120133    errno = 0;
    121134    v = strtol(arg, &endptr, base);
     
    125138}
    126139#endif
    127 
    128 /* Floating point */
    129 
    130 #if 0
    131 
    132 #include <math.h>  /* just for HUGE_VAL */
    133 #define NOT_DIGIT(a) (((unsigned char)(a-'0')) > 9)
    134 double bb_strtod(const char *arg, char **endp)
    135 {
    136     double v;
    137     char *endptr;
    138 
    139     if (arg[0] != '-' && NOT_DIGIT(arg[0])) goto err;
    140     errno = 0;
    141     v = strtod(arg, &endptr);
    142     if (endp) *endp = endptr;
    143     if (endptr[0]) {
    144         /* "1234abcg" or out-of-range? */
    145         if (isalnum(endptr[0]) || errno) {
    146  err:
    147             errno = ERANGE;
    148             return HUGE_VAL;
    149         }
    150         /* good number, just suspicious terminator */
    151         errno = EINVAL;
    152     }
    153     return v;
    154 }
    155 
    156 #endif
Note: See TracChangeset for help on using the changeset viewer.