Changeset 6e716a59 in mainline for generic/src/lib/func.c


Ignore:
Timestamp:
2005-12-10T15:05:46Z (20 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
72f5866d
Parents:
a3ac9a7
Message:

Added calling of generic functions to kconsole.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/lib/func.c

    ra3ac9a7 r6e716a59  
    114114        }
    115115}
     116
     117/** Convert ascii representation to __native
     118 *
     119 * Supports 0x for hexa & 0 for octal notation.
     120 * Does not check for overflows, does not support negative numbers
     121 *
     122 * @param text Textual representation of number
     123 * @return Converted number or 0 if no valid number ofund
     124 */
     125__native atoi(const char *text)
     126{
     127        int base = 10;
     128        __native result = 0;
     129
     130        if (text[0] == '0' && text[1] == 'x') {
     131                base = 16;
     132                text += 2;
     133        } else if (text[0] == '0')
     134                base = 8;
     135
     136        while (*text) {
     137                result *= base;
     138                if (base != 16 && *text >= 'A' && *text <= 'F')
     139                        break;
     140                if (base == 8 && *text >='8')
     141                        break;
     142
     143                if (*text >= '0' && *text <= '9')
     144                        result += *text - '0';
     145                else if (*text >= 'A' && *text <= 'F')
     146                        result += *text - 'A' + 10;
     147                else
     148                        break;
     149                text++;
     150        }
     151
     152        return result;
     153}
Note: See TracChangeset for help on using the changeset viewer.