[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH v3 1/3] lib/nolibc: Introduce atoi() function
Reviewed-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx> Simon Kuenzer <simon.kuenzer@xxxxxxxxx> writes: > From: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> > > Adds atoi() conversion function to stdlib. It is based on strtoll(). > > Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> > Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> > --- > lib/nolibc/include/stdlib.h | 6 ++++++ > lib/nolibc/stdlib.c | 11 +++++++++++ > 2 files changed, 17 insertions(+) > > diff --git a/lib/nolibc/include/stdlib.h b/lib/nolibc/include/stdlib.h > index dd6f9f7..f2a0ccf 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..22afa77 100644 > --- a/lib/nolibc/stdlib.c > +++ b/lib/nolibc/stdlib.c > @@ -276,3 +276,14 @@ 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) > +{ > + long long atoll; > + > + atoll = strtoll(s, NULL, 10); > + atoll = (atoll > __I_MAX) ? __I_MAX : atoll; > + atoll = (atoll < __I_MIN) ? __I_MIN : atoll; > + > + return (int) atoll; > +} > -- > 2.7.4 > -- 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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |