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

Re: [Minios-devel] [UNIKRAFT PATCH 1/5] lib/nolibc: Extending the nolibc to support atoi function



Actually just a TODO for now would be enough 

Yuri Volchkov <yuri.volchkov@xxxxxxxxx> writes:

> Sharan Santhanam <sharan.santhanam@xxxxxxxxx> writes:
>
>> Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
>> ---
>>  lib/nolibc/include/stdlib.h | 6 ++++++
>>  lib/nolibc/stdlib.c         | 5 +++++
>>  2 files changed, 11 insertions(+)
>>
>> diff --git a/lib/nolibc/include/stdlib.h b/lib/nolibc/include/stdlib.h
>> index dd6f9f7..12bc086 100644
>> --- a/lib/nolibc/include/stdlib.h
>> +++ b/lib/nolibc/include/stdlib.h
>> @@ -48,6 +48,12 @@ unsigned long strtoul(const char *nptr, char **endptr, 
>> int base);
>>  long long strtoll(const char *nptr, char **endptr, int base);
>>  unsigned long long strtoull(const char *nptr, char **endptr, int base);
>>  
>> +/**
>> + * Convert a string to an integer
>> + * @s: The start of the string
>> + */
>> +int atoi (const char *s);
>> +
>>  #if CONFIG_LIBUKALLOC
>>  /* Allocate size bytes of memory. Returns pointer to start of allocated 
>> memory,
>>   * or NULL on failure.
>> diff --git a/lib/nolibc/stdlib.c b/lib/nolibc/stdlib.c
>> index d48083a..e6d162b 100644
>> --- a/lib/nolibc/stdlib.c
>> +++ b/lib/nolibc/stdlib.c
>> @@ -276,3 +276,8 @@ unsigned long long strtoull(const char *nptr, char 
>> **endptr, int base)
>>              *endptr = __DECONST(char *, any ? s - 1 : nptr);
>>      return acc;
>>  }
>> +
>> +int atoi (const char *s)
>> +{
>> +    return (int) strtoll (s, NULL, 10);
>> +}
> The function strtoll returns long long which is 8 bytes. We need to
> check limits before returning int. According to the man strtol:
>
>   "The strtol() function returns the result of the conversion, unless
>    the value would underflow or overflow.  If an underflow occurs,
>    strtol() returns LONG_MIN.  If an overflow occurs, strtol() returns
>    LONG_MAX.  In both cases, errno is set to ERANGE.  Precisely the same
>    holds for strtoll() (with LLONG_MIN and LLONG_MAX instead of LONG_MIN
>    and LONG_MAX)."
>> -- 
>> 2.7.4
>>
>>
>> _______________________________________________
>> Minios-devel mailing list
>> Minios-devel@xxxxxxxxxxxxxxxxxxxx
>> https://lists.xenproject.org/mailman/listinfo/minios-devel
>
> -- 
> Yuri Volchkov
> Software Specialist
>
> NEC Europe Ltd
> Kurfürsten-Anlage 36
> D-69115 Heidelberg

-- 
Yuri Volchkov
Software Specialist

NEC Europe Ltd
Kurfürsten-Anlage 36
D-69115 Heidelberg

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.