2 * (C) Copyright 2007-2010 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
8 static char* __extract_dec(char *str
, u64
*val
)
15 return ERR_PTR(-EINVAL
);
20 for (; str
&& *str
!= '\0'; str
++, len
++) {
21 if (*str
>= '0' && *str
<= '9')
23 else if (*str
== ' ' || *str
== '\t')
26 return ERR_PTR(-EINVAL
);
28 res
= (res
* 10) + tmp
;
32 return ERR_PTR(-EINVAL
);
39 static char* __extract_hex(char *str
, u64
*val
)
46 return ERR_PTR(-EINVAL
);
51 for (; str
&& *str
!= '\0'; str
++, len
++) {
52 if (*str
>= '0' && *str
<= '9')
54 else if (*str
>= 'A' && *str
<= 'F')
55 tmp
= *str
- 'A' + 10;
56 else if (*str
>= 'a' && *str
<= 'f')
57 tmp
= *str
- 'a' + 10;
58 else if (*str
== ' ' || *str
== '\t')
61 return ERR_PTR(-EINVAL
);
63 res
= (res
<< 4) | tmp
;
67 return ERR_PTR(-EINVAL
);
74 static char* __consume_ws(char *str
)
79 /* consume any extra whitespace */
80 while(*str
== ' ' || *str
== '\t')