Ignore:
File:
1 edited

Legend:

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

    r4ce914d4 re535eeb  
    2727 */
    2828
    29 /** @addtogroup generic
     29/** @addtogroup generic 
    3030 * @{
    3131 */
     
    3333/**
    3434 * @file
    35  * @brief Miscellaneous functions.
     35 * @brief       Miscellaneous functions.
    3636 */
    3737
     
    7979}
    8080
     81/** Convert ascii representation to unative_t
     82 *
     83 * Supports 0x for hexa & 0 for octal notation.
     84 * Does not check for overflows, does not support negative numbers
     85 *
     86 * @param text Textual representation of number
     87 * @return Converted number or 0 if no valid number ofund
     88 */
     89unative_t atoi(const char *text)
     90{
     91        int base = 10;
     92        unative_t result = 0;
     93
     94        if (text[0] == '0' && text[1] == 'x') {
     95                base = 16;
     96                text += 2;
     97        } else if (text[0] == '0')
     98                base = 8;
     99
     100        while (*text) {
     101                if (base != 16 && \
     102                    ((*text >= 'A' && *text <= 'F' )
     103                     || (*text >='a' && *text <='f')))
     104                        break;
     105                if (base == 8 && *text >='8')
     106                        break;
     107
     108                if (*text >= '0' && *text <= '9') {
     109                        result *= base;
     110                        result += *text - '0';
     111                } else if (*text >= 'A' && *text <= 'F') {
     112                        result *= base;
     113                        result += *text - 'A' + 10;
     114                } else if (*text >= 'a' && *text <= 'f') {
     115                        result *= base;
     116                        result += *text - 'a' + 10;
     117                } else
     118                        break;
     119                text++;
     120        }
     121
     122        return result;
     123}
     124
    81125/** @}
    82126 */
Note: See TracChangeset for help on using the changeset viewer.