Skip to content

Commit 7158fea

Browse files
author
Me No Dev
committed
Merge remote-tracking branch 'esp8266/master'
2 parents e2ff86b + 6d3109e commit 7158fea

File tree

4 files changed

+88
-61
lines changed

4 files changed

+88
-61
lines changed

cores/esp8266/core_esp8266_noniso.c

-61
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@
2929
#include <math.h>
3030
#include "stdlib_noniso.h"
3131

32-
33-
int atoi(const char* s) {
34-
return (int) atol(s);
35-
}
36-
37-
long atol(const char* s) {
38-
char * tmp;
39-
return strtol(s, &tmp, 10);
40-
}
41-
42-
double atof(const char* s) {
43-
char * tmp;
44-
return strtod(s, &tmp);
45-
}
46-
4732
void reverse(char* begin, char* end) {
4833
char *is = begin;
4934
char *ie = end - 1;
@@ -56,31 +41,6 @@ void reverse(char* begin, char* end) {
5641
}
5742
}
5843

59-
char* itoa(int value, char* result, int base) {
60-
if(base < 2 || base > 16) {
61-
*result = 0;
62-
return result;
63-
}
64-
65-
char* out = result;
66-
int quotient = abs(value);
67-
68-
do {
69-
const int tmp = quotient / base;
70-
*out = "0123456789abcdef"[quotient - (tmp * base)];
71-
++out;
72-
quotient = tmp;
73-
} while(quotient);
74-
75-
// Apply negative sign
76-
if(value < 0)
77-
*out++ = '-';
78-
79-
reverse(result, out);
80-
*out = 0;
81-
return result;
82-
}
83-
8444
char* ltoa(long value, char* result, int base) {
8545
if(base < 2 || base > 16) {
8646
*result = 0;
@@ -106,27 +66,6 @@ char* ltoa(long value, char* result, int base) {
10666
return result;
10767
}
10868

109-
char* utoa(unsigned value, char* result, int base) {
110-
if(base < 2 || base > 16) {
111-
*result = 0;
112-
return result;
113-
}
114-
115-
char* out = result;
116-
unsigned quotient = value;
117-
118-
do {
119-
const unsigned tmp = quotient / base;
120-
*out = "0123456789abcdef"[quotient - (tmp * base)];
121-
++out;
122-
quotient = tmp;
123-
} while(quotient);
124-
125-
reverse(result, out);
126-
*out = 0;
127-
return result;
128-
}
129-
13069
char* ultoa(unsigned long value, char* result, int base) {
13170
if(base < 2 || base > 16) {
13271
*result = 0;

cores/esp8266/stdlib_noniso.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ char* ultoa (unsigned long val, char *s, int radix);
4242

4343
char* dtostrf (double val, signed char width, unsigned char prec, char *s);
4444

45+
void reverse(char* begin, char* end);
46+
4547
#ifdef __cplusplus
4648
} // extern "C"
4749
#endif

tests/host/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ MOCK_CPP_FILES := $(addprefix common/,\
3737

3838
MOCK_C_FILES := $(addprefix common/,\
3939
md5.c \
40+
noniso.c \
4041
)
4142

4243
INC_PATHS += $(addprefix -I, \

tests/host/common/noniso.c

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
noniso.cpp - replacements for non-ISO functions used by Arduino core
3+
Copyright © 2016 Ivan Grokhotkov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
*/
15+
16+
17+
#include <stdlib.h>
18+
#include <string.h>
19+
#include <stdbool.h>
20+
#include <stdint.h>
21+
#include <math.h>
22+
#include "stdlib_noniso.h"
23+
24+
25+
26+
char* utoa(unsigned value, char* result, int base) {
27+
if(base < 2 || base > 16) {
28+
*result = 0;
29+
return result;
30+
}
31+
32+
char* out = result;
33+
unsigned quotient = value;
34+
35+
do {
36+
const unsigned tmp = quotient / base;
37+
*out = "0123456789abcdef"[quotient - (tmp * base)];
38+
++out;
39+
quotient = tmp;
40+
} while(quotient);
41+
42+
reverse(result, out);
43+
*out = 0;
44+
return result;
45+
}
46+
47+
char* itoa(int value, char* result, int base) {
48+
if(base < 2 || base > 16) {
49+
*result = 0;
50+
return result;
51+
}
52+
53+
char* out = result;
54+
int quotient = abs(value);
55+
56+
do {
57+
const int tmp = quotient / base;
58+
*out = "0123456789abcdef"[quotient - (tmp * base)];
59+
++out;
60+
quotient = tmp;
61+
} while(quotient);
62+
63+
// Apply negative sign
64+
if(value < 0)
65+
*out++ = '-';
66+
67+
reverse(result, out);
68+
*out = 0;
69+
return result;
70+
}
71+
72+
int atoi(const char* s) {
73+
return (int) atol(s);
74+
}
75+
76+
long atol(const char* s) {
77+
char * tmp;
78+
return strtol(s, &tmp, 10);
79+
}
80+
81+
double atof(const char* s) {
82+
char * tmp;
83+
return strtod(s, &tmp);
84+
}
85+

0 commit comments

Comments
 (0)