Patchwork [2/2] strtosz() use toupper() to simplify switch statement

login
register
mail settings
Submitter Jes Sorensen
Date Jan. 17, 2011, 3:14 p.m.
Message ID <1295277257-17425-3-git-send-email-Jes.Sorensen@redhat.com>
Download mbox | patch
Permalink /patch/79188/
State New
Headers show

Comments

Jes Sorensen - Jan. 17, 2011, 3:14 p.m.
From: Jes Sorensen <Jes.Sorensen@redhat.com>

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 cutils.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
Blue Swirl - Jan. 17, 2011, 7:57 p.m.
On Mon, Jan 17, 2011 at 3:14 PM,  <Jes.Sorensen@redhat.com> wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  cutils.c |    7 +------
>  1 files changed, 1 insertions(+), 6 deletions(-)
>
> diff --git a/cutils.c b/cutils.c
> index f97ef39..f7aa90c 100644
> --- a/cutils.c
> +++ b/cutils.c
> @@ -323,16 +323,14 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
>             d = c;
>         }
>     }
> -    switch (d) {
> +    switch (toupper(d)) {

qemu_toupper()

Patch

diff --git a/cutils.c b/cutils.c
index f97ef39..f7aa90c 100644
--- a/cutils.c
+++ b/cutils.c
@@ -323,16 +323,14 @@  ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             d = c;
         }
     }
-    switch (d) {
+    switch (toupper(d)) {
     case 'B':
-    case 'b':
         mul = 1;
         if (mul_required) {
             goto fail;
         }
         break;
     case 'K':
-    case 'k':
         mul = 1 << 10;
         break;
     case 0:
@@ -340,15 +338,12 @@  ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
             goto fail;
         }
     case 'M':
-    case 'm':
         mul = 1ULL << 20;
         break;
     case 'G':
-    case 'g':
         mul = 1ULL << 30;
         break;
     case 'T':
-    case 't':
         mul = 1ULL << 40;
         break;
     default: