Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 3ae4752

Browse files
enh-googleGerrit Code Review
authored andcommitted
Merge "<stdlib.h>: ato*()/strto*() cleanup." into main
2 parents 2239545 + 14a5588 commit 3ae4752

File tree

2 files changed

+115
-21
lines changed

2 files changed

+115
-21
lines changed

libc/include/android/legacy_stdlib_inlines.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ static __inline float strtof_l(const char* _Nonnull __s, char* _Nullable * _Null
4646
return strtof(__s, __end_ptr);
4747
}
4848

49-
static __inline long strtol_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l) {
50-
return strtol(__s, __end_ptr, __base);
51-
}
52-
5349
__END_DECLS
5450

5551
#endif

libc/include/stdlib.h

Lines changed: 115 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ int mkstemp(char* _Nonnull __template);
6868
int mkstemps64(char* _Nonnull __template, int __flags) __INTRODUCED_IN(23);
6969
int mkstemps(char* _Nonnull __template, int __flags);
7070

71-
long strtol(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
72-
long long strtoll(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
73-
unsigned long strtoul(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
74-
unsigned long long strtoull(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
75-
7671
int posix_memalign(void* _Nullable * _Nullable __memptr, size_t __alignment, size_t __size);
7772

7873
/**
@@ -86,15 +81,6 @@ int posix_memalign(void* _Nullable * _Nullable __memptr, size_t __alignment, siz
8681
*/
8782
__wur void* _Nullable aligned_alloc(size_t __alignment, size_t __size) __INTRODUCED_IN(28);
8883

89-
double strtod(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr);
90-
long double strtold(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr);
91-
92-
unsigned long strtoul_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l) __INTRODUCED_IN(26);
93-
94-
int atoi(const char* _Nonnull __s) __attribute_pure__;
95-
long atol(const char* _Nonnull __s) __attribute_pure__;
96-
long long atoll(const char* _Nonnull __s) __attribute_pure__;
97-
9884
__wur char* _Nullable realpath(const char* _Nonnull __path, char* _Nullable __resolved);
9985

10086
/**
@@ -219,22 +205,134 @@ int abs(int __x) __attribute_const__;
219205
long labs(long __x) __attribute_const__;
220206
long long llabs(long long __x) __attribute_const__;
221207

222-
float strtof(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr);
223-
double atof(const char* _Nonnull __s) __attribute_pure__;
224208
int rand(void);
225209
void srand(unsigned int __seed);
226210
long random(void);
227211
void srandom(unsigned int __seed);
228212
int grantpt(int __fd);
229213

214+
/**
215+
* [atof(3)](https://man7.org/linux/man-pages/man3/atof.3.html) converts a
216+
* string to a double.
217+
*
218+
* Returns the double; use strtof() or strtod() if you need to detect errors.
219+
*/
220+
double atof(const char* _Nonnull __s) __attribute_pure__;
221+
222+
/**
223+
* [atoi(3)](https://man7.org/linux/man-pages/man3/atoi.3.html) converts a
224+
* string to an int.
225+
*
226+
* Returns the int or 0 on error; use strtol() if you need to detect errors.
227+
*/
228+
int atoi(const char* _Nonnull __s) __attribute_pure__;
229+
230+
/**
231+
* [atol(3)](https://man7.org/linux/man-pages/man3/atol.3.html) converts a
232+
* string to a long.
233+
*
234+
* Returns the long or 0 on error; use strtol() if you need to detect errors.
235+
*/
236+
long atol(const char* _Nonnull __s) __attribute_pure__;
237+
238+
/**
239+
* [atoll(3)](https://man7.org/linux/man-pages/man3/atoll.3.html) converts a
240+
* string to a long long.
241+
*
242+
* Returns the long long or 0 on error; use strtol() if you need to detect errors.
243+
*/
244+
long long atoll(const char* _Nonnull __s) __attribute_pure__;
245+
246+
/**
247+
* [strtol(3)](https://man7.org/linux/man-pages/man3/strtol.3.html) converts a
248+
* string to a long.
249+
*
250+
* Returns the long.
251+
* `__end_ptr` is set to the last character in `__s` that was converted.
252+
* errno is set to ERANGE if the result overflowed or underflowed.
253+
*/
254+
long strtol(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
255+
256+
/** Equivalent to strtol() on Android. */
257+
long strtol_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int, locale_t _Nonnull __l) __RENAME(strtol);
258+
259+
/**
260+
* [strtoll(3)](https://man7.org/linux/man-pages/man3/strtoll.3.html) converts a
261+
* string to a long long.
262+
*
263+
* Returns the long long.
264+
* `__end_ptr` is set to the last character in `__s` that was converted.
265+
* errno is set to ERANGE if the result overflowed or underflowed.
266+
*/
267+
long long strtoll(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
268+
269+
/** Equivalent to strtoll() on Android. */
230270
long long strtoll_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l);
271+
272+
/**
273+
* [strtoul(3)](https://man7.org/linux/man-pages/man3/strtoul.3.html) converts a
274+
* string to an unsigned long.
275+
*
276+
* Returns the unsigned long.
277+
* `__end_ptr` is set to the last character in `__s` that was converted.
278+
* errno is set to ERANGE if the result overflowed or underflowed.
279+
*/
280+
unsigned long strtoul(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
281+
282+
/** Equivalent to strtoul() on Android. */
283+
unsigned long strtoul_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l) __RENAME(strtoul);
284+
285+
/**
286+
* [strtoull(3)](https://man7.org/linux/man-pages/man3/strtoull.3.html) converts a
287+
* string to an unsigned long long.
288+
*
289+
* Returns the unsigned long long.
290+
* `__end_ptr` is set to the last character in `__s` that was converted.
291+
* errno is set to ERANGE if the result overflowed or underflowed.
292+
*/
293+
unsigned long long strtoull(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base);
294+
295+
/** Equivalent to strtoull() on Android. */
231296
unsigned long long strtoull_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int __base, locale_t _Nonnull __l);
297+
298+
/**
299+
* [strtof(3)](https://man7.org/linux/man-pages/man3/strtof.3.html) converts a
300+
* string to a float.
301+
*
302+
* Returns the float.
303+
* `__end_ptr` is set to the last character in `__s` that was converted.
304+
* errno is set to ERANGE if the result overflowed or underflowed.
305+
*/
306+
float strtof(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr);
307+
308+
/**
309+
* [strtod(3)](https://man7.org/linux/man-pages/man3/strtod.3.html) converts a
310+
* string to a double.
311+
*
312+
* Returns the double.
313+
* `__end_ptr` is set to the last character in `__s` that was converted.
314+
* errno is set to ERANGE if the result overflowed or underflowed.
315+
*/
316+
double strtod(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr);
317+
318+
/**
319+
* [strtold(3)](https://man7.org/linux/man-pages/man3/strtold.3.html) converts a
320+
* string to a long double.
321+
*
322+
* Returns the long double.
323+
* `__end_ptr` is set to the last character in `__s` that was converted.
324+
* errno is set to ERANGE if the result overflowed or underflowed.
325+
*/
326+
long double strtold(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr);
327+
328+
/** Equivalent to strtold() on Android. */
232329
long double strtold_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, locale_t _Nonnull __l);
233330

234331
#if __ANDROID_API__ >= 26
332+
/** Equivalent to strtod() on Android. */
235333
double strtod_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, locale_t _Nonnull __l) __INTRODUCED_IN(26);
334+
/** Equivalent to strtof() on Android. */
236335
float strtof_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, locale_t _Nonnull __l) __INTRODUCED_IN(26);
237-
long strtol_l(const char* _Nonnull __s, char* _Nullable * _Nullable __end_ptr, int, locale_t _Nonnull __l) __INTRODUCED_IN(26);
238336
#else
239337
// Implemented as static inlines before 26.
240338
#endif

0 commit comments

Comments
 (0)