[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [qemu-s390x] [PATCH v5 04/12] s390-ccw: update libc
From: |
Thomas Huth |
Subject: |
Re: [qemu-s390x] [PATCH v5 04/12] s390-ccw: update libc |
Date: |
Tue, 6 Feb 2018 07:14:27 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 05.02.2018 21:57, Collin L. Walling 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
>
> Added non C-standard function:
> itostr
> atoui
>
> Signed-off-by: Collin L. Walling <address@hidden>
> Acked-by: Christian Borntraeger <address@hidden>
> Reviewed-by: Janosch Frank <address@hidden>
> ---
[...]
> +/**
> + * itostr:
> + * @num: an integer (base 10) to be converted.
> + * @str: a pointer to a string to store the conversion.
> + * @len: the length of the passed string.
> + *
> + * Given an integer @num, convert it to a string. The string @str must be
> + * allocated beforehand. The resulting string will be null terminated and
> + * returned. This function only handles numbers between 0 and UINT64_MAX
> + * inclusive.
> + *
> + * Returns: the string @str of the converted integer @num; NULL if @str
> + * is NULL or if there is not enough space allocated.
> + */
> +char *itostr(uint64_t num, char *str, size_t len)
Nitpicking: You renamed atoi to atoui, so maybe this should now rather
be uitostr or uitoa now?
> +{
> + size_t num_idx = 0;
> + uint64_t tmp = num;
> +
> + IPL_assert(num >= 0, "itostr: cannot convert negative values");
(already mentioned by patchew)
> + IPL_assert(str != NULL, "itostr: no space allocated to store string");
> +
> + /* Get index to ones place */
> + while ((tmp /= 10) != 0) {
> + num_idx++;
> + }
> +
> + /* Check if we have enough space for num and null */
> + IPL_assert(len >= num_idx + 1, "itostr: array too small for conversion");
Should that rather be "len > num_idx + 1" instead?
> + str[num_idx + 1] = '\0';
> +
> + /* Convert int to string */
> + while (num_idx >= 0) {
> + str[num_idx] = num % 10 + '0';
> + num /= 10;
> + num_idx--;
> + }
> +
> + return str;
> +}
Thomas
[qemu-s390x] [PATCH v5 04/12] s390-ccw: update libc, Collin L. Walling, 2018/02/05
- Re: [qemu-s390x] [PATCH v5 04/12] s390-ccw: update libc,
Thomas Huth <=
[qemu-s390x] [PATCH v5 09/12] s390-ccw: print zipl boot menu, Collin L. Walling, 2018/02/05
[qemu-s390x] [PATCH v5 11/12] s390-ccw: clear pending irqs, Collin L. Walling, 2018/02/05