unsigned long ustrtoul(const char *cp, char **endp, unsigned int base)
{
unsigned long result = simple_strtoul(cp, endp, base);
- switch (**endp) {
- case 'G':
+ switch (tolower(**endp)) {
+ case 'g':
result *= 1024;
/* fall through */
- case 'M':
+ case 'm':
result *= 1024;
/* fall through */
- case 'K':
case 'k':
result *= 1024;
- if ((*endp)[1] == 'i') {
- if ((*endp)[2] == 'B')
- (*endp) += 3;
- else
- (*endp) += 2;
- }
+ (*endp)++;
+ if (**endp == 'i')
+ (*endp)++;
+ if (**endp == 'B')
+ (*endp)++;
}
return result;
}
unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base)
{
unsigned long long result = simple_strtoull(cp, endp, base);
- switch (**endp) {
- case 'G':
+ switch (tolower(**endp)) {
+ case 'g':
result *= 1024;
/* fall through */
- case 'M':
+ case 'm':
result *= 1024;
/* fall through */
- case 'K':
case 'k':
result *= 1024;
- if ((*endp)[1] == 'i') {
- if ((*endp)[2] == 'B')
- (*endp) += 3;
- else
- (*endp) += 2;
- }
+ (*endp)++;
+ if (**endp == 'i')
+ (*endp)++;
+ if (**endp == 'B')
+ (*endp)++;
}
return result;
}