Changeset 4ce914d4 in mainline for kernel/generic/src/lib/func.c
- Timestamp:
- 2010-04-30T23:10:12Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0c42638, bb252ca
- Parents:
- bcb6f27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/lib/func.c
rbcb6f27 r4ce914d4 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Miscellaneous functions. 36 36 */ 37 37 … … 79 79 } 80 80 81 /** Convert ascii representation to unative_t82 *83 * Supports 0x for hexa & 0 for octal notation.84 * Does not check for overflows, does not support negative numbers85 *86 * @param text Textual representation of number87 * @return Converted number or 0 if no valid number ofund88 */89 unative_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 } else118 break;119 text++;120 }121 122 return result;123 }124 125 81 /** @} 126 82 */
Note:
See TracChangeset
for help on using the changeset viewer.