qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v1 1/5] s390-ccw: update libc.h


From: Cornelia Huck
Subject: Re: [Qemu-devel] [PATCH v1 1/5] s390-ccw: update libc.h
Date: Tue, 28 Nov 2017 11:45:58 +0100

On Mon, 27 Nov 2017 15:55:32 -0500
"Collin L. Walling" <address@hidden> wrote:

> Moved:
>   memcmp from bootmap.h to libc.h (renamed from _memcmp)
>   strlen from sclp.c to libc.h (renamed from _strlen)
> 
> Added C standard functions:
>   isdigit
>   atoi
> 
> Added non-C standard function:
>   itostr
> 
> Signed-off-by: Collin L. Walling <address@hidden>
> Acked-by: Christian Borntraeger <address@hidden>
> Reviewed-by: address@hidden

You might want to include Janosch's complete name :)

> ---
>  pc-bios/s390-ccw/bootmap.c |  4 +-
>  pc-bios/s390-ccw/bootmap.h | 16 +-------
>  pc-bios/s390-ccw/libc.h    | 94 
> ++++++++++++++++++++++++++++++++++++++++++++++
>  pc-bios/s390-ccw/main.c    | 17 +--------
>  pc-bios/s390-ccw/sclp.c    | 10 +----
>  5 files changed, 99 insertions(+), 42 deletions(-)
> 

> diff --git a/pc-bios/s390-ccw/libc.h b/pc-bios/s390-ccw/libc.h
> index 0142ea8..703c34d 100644
> --- a/pc-bios/s390-ccw/libc.h
> +++ b/pc-bios/s390-ccw/libc.h

(...)

> +/* itostr
> + *
> + * Given an integer, convert it to a string. The string must be allocated
> + * beforehand. The resulting string will be null terminated and returned.
> + *
> + * @str - the integer to be converted
> + * @num - a pointer to a string to store the conversion
> + *
> + * @return - the string of the converted integer
> + */

That one's a bit unusual as it does not match the semantics of any
library function I'd normally use for that kind of thing, but it seems
to do the job and more would be overkill, so fine with me.

> +static inline char *itostr(int num, char *str)
> +{
> +    int i;
> +    int len = 0;
> +    long tens = 1;
> +
> +    /* Handle 0 */
> +    if (num == 0) {
> +        str[0] = '0';
> +        str[1] = '\0';
> +        return str;
> +    }
> +
> +    /* Count number of digits */
> +    while (num / tens != 0) {
> +        tens *= 10;
> +        len++;
> +    }
> +
> +    /* Convert int -> string */
> +    for (i = 0; i < len; i++) {
> +        tens /= 10;
> +        str[i] = num / tens % 10 + '0';
> +    }
> +
> +    str[i] = '\0';
> +
> +    return str;
> +}
> +
>  #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]