options/ansi: handle strings starting with '+' in strtol
Signed-off-by: Dennis Bonke <admin@dennisbonke.com>
This commit is contained in:
parent
32a3864c6b
commit
31d799ce24
|
@ -75,12 +75,13 @@ long strtol(const char *__restrict string, char **__restrict end, int base) {
|
|||
|
||||
// skip leading space
|
||||
while(*string) {
|
||||
if(*string == '+')
|
||||
string++;
|
||||
if(!isspace(*string))
|
||||
break;
|
||||
string++;
|
||||
}
|
||||
|
||||
__ensure(*string != '+');
|
||||
bool negative = false;
|
||||
if(*string == '-') {
|
||||
negative = true;
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
#include <assert.h>
|
||||
|
||||
int main () {
|
||||
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
|
||||
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff +2001";
|
||||
char *pEnd;
|
||||
long int li1, li2, li3, li4;
|
||||
li1 = strtol (szNumbers, &pEnd, 10);
|
||||
li2 = strtol (pEnd, &pEnd, 16);
|
||||
li3 = strtol (pEnd, &pEnd, 2);
|
||||
li4 = strtol (pEnd, NULL, 0);
|
||||
long int li1, li2, li3, li4, li5;
|
||||
li1 = strtol(szNumbers, &pEnd, 10);
|
||||
li2 = strtol(pEnd, &pEnd, 16);
|
||||
li3 = strtol(pEnd, &pEnd, 2);
|
||||
li4 = strtol(pEnd, &pEnd, 0);
|
||||
li5 = strtol(pEnd, NULL, 10);
|
||||
assert(li1 == 2001);
|
||||
assert(li2 == 6340800);
|
||||
assert(li3 == -3624224);
|
||||
assert(li4 == 7340031);
|
||||
assert(li5 == 2001);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue