1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Remove broken ltoa/ultoa, call itoa/utoa (#5625)

* Remove broken ltoa/ultoa, call itoa/utoa

Use the newlib integer-to-ASCII non-POSIX calls instead of rolling
our own.  Should be safe as sizeof(long) == sizeof(int).
The custom functions behaved differently from itoa when passed in
negative values in non-base-10.

Add host tests for negative non-base-10 int/longs
This commit is contained in:
Earle F. Philhower, III
2019-01-17 02:08:19 +00:00
committed by GitHub
parent 7ee503d353
commit 6883beedec
3 changed files with 25 additions and 52 deletions

View File

@ -22,6 +22,17 @@
#include "stdlib_noniso.h"
void reverse(char* begin, char* end) {
char *is = begin;
char *ie = end - 1;
while(is < ie) {
char tmp = *ie;
*ie = *is;
*is = tmp;
++is;
--ie;
}
}
char* utoa(unsigned value, char* result, int base) {
if(base < 2 || base > 16) {
@ -49,6 +60,9 @@ char* itoa(int value, char* result, int base) {
*result = 0;
return result;
}
if (base != 10) {
return utoa((unsigned)value, result, base);
}
char* out = result;
int quotient = abs(value);