X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Fstrto.c;h=c00bb5895df42b8a113e818c3e99290f4e142c20;hb=164873a0c02ddbc9a59ad3a0670f17684fc00737;hp=7f6076909ab7401e802eac798671b79c0515a0b7;hpb=2e794614838292499910060509d3c4a7aaed986a;p=oweals%2Fu-boot.git diff --git a/lib/strto.c b/lib/strto.c index 7f6076909a..c00bb5895d 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -85,22 +85,20 @@ long simple_strtol(const char *cp, char **endp, unsigned int base) 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; } @@ -108,22 +106,20 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base) 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; } @@ -167,3 +163,11 @@ long trailing_strtol(const char *str) { return trailing_strtoln(str, NULL); } + +void str_to_upper(const char *in, char *out, size_t len) +{ + for (; len > 0 && *in; len--) + *out++ = toupper(*in++); + if (len) + *out = '\0'; +}