[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [qemu-s390x] [Qemu-devel] [PATCH v3 1/8] s390-ccw: update libc
From: |
Thomas Huth |
Subject: |
Re: [qemu-s390x] [Qemu-devel] [PATCH v3 1/8] s390-ccw: update libc |
Date: |
Tue, 16 Jan 2018 11:00:54 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 |
On 15.01.2018 18:23, Collin L. Walling wrote:
> On 01/15/2018 12:05 PM, Eric Blake wrote:
>> On 01/15/2018 10:44 AM, Collin L. Walling wrote:
[...]
>>> +/**
>>> + * atoi:
>>> + * @str: the string to be converted.
>>> + *
>>> + * Given a string @str, convert it to an integer. Any non-numerical
>>> value
>>> + * will terminate the conversion.
>>> + *
>>> + * Returns: an integer converted from the string @str.
>>> + */
>>> +int atoi(const char *str)
>>> +{
>>> + int i;
>>> + int val = 0;
>>> +
>>> + for (i = 0; str[i]; i++) {
>>> + char c = str[i];
>>> + if (!isdigit(c)) {
>>> + break;
>>> + }
>>> + val *= 10;
>>> + val += c - '0';
>> Silently gives garbage on integer overflow, but matches the fact that
>> POSIX atoi() can't flag errors. However, it does not handle leading
>> whitespace nor '-', which means it is NOT doing a POSIX-compatible
>> atoi() implementation; naming it atoi() is perhaps thus a disservice to
>> end users.
>
> Fair enough. Perhaps the "strtoi" convention suits this better.
Or maybe simply add an assert(str[0] != '-') for now. If we ever hit the
assert, we can still add the support for negative numbers if necessary.
>>> +static inline size_t strlen(const char *str)
>>> +{
>>> + size_t i;
>>> + for (i = 0; *str; i++) {
>>> + str++;
>>> + }
>>> + return i;
>> Again, not the fastest implementation, but that shouldn't matter.
Yes, indeed, speed does not really matter here for the some few bytes
that are handled during the life-time of the s390-ccw bios.
>>> +}
>>> +
>>> +static inline int isdigit(int c)
>>> +{
>>> + return (c >= '0') && (c <= '9');
>>> +}
>>> +
>>> +int atoi(const char *str);
>>> +char *itostr(int num, char *str, size_t len);
>>> +
>>> #endif
>
>
Thomas
[qemu-s390x] [PATCH v3 3/8] s390-ccw: parse and set boot menu options, Collin L. Walling, 2018/01/15
[qemu-s390x] [PATCH v3 2/8] s390-ccw: ipl structs for eckd cdl/ldl, Collin L. Walling, 2018/01/15