diff options
-rw-r--r-- | firmware/common/atoi.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/firmware/common/atoi.c b/firmware/common/atoi.c index 4911d93e92..59887ec9fa 100644 --- a/firmware/common/atoi.c +++ b/firmware/common/atoi.c | |||
@@ -17,15 +17,38 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include "string.h" | 20 | #include "ctype.h" |
21 | 21 | ||
22 | int atoi (const char *str) | 22 | int atoi (const char *str) |
23 | { | 23 | { |
24 | int val = 0, mlt = 1; | 24 | int value = 0; |
25 | char *p; | 25 | int sign = 1; |
26 | p = (char *) (str + strlen(str) - 1); | 26 | |
27 | for (; p >= str; --p, mlt *=10) | 27 | while (isspace(*str)) |
28 | val += (mlt * ((int)*p - '0')); | 28 | { |
29 | return val; | 29 | str++; |
30 | } | 30 | } |
31 | |||
32 | if ('-' == *str) | ||
33 | { | ||
34 | sign = -1; | ||
35 | str++; | ||
36 | } | ||
37 | else if ('+' == *str) | ||
38 | { | ||
39 | str++; | ||
40 | } | ||
41 | |||
42 | while ('0' == *str) | ||
43 | { | ||
44 | str++; | ||
45 | } | ||
31 | 46 | ||
47 | while (isdigit(*str)) | ||
48 | { | ||
49 | value = (value * 10) + (*str - '0'); | ||
50 | str++; | ||
51 | } | ||
52 | |||
53 | return value * sign; | ||
54 | } | ||