options/ansi: handle strings starting with '+' in strtol

Signed-off-by: Dennis Bonke <admin@dennisbonke.com>
This commit is contained in:
Dennis Bonke 2021-02-03 19:03:21 +01:00
parent 32a3864c6b
commit 31d799ce24
No known key found for this signature in database
GPG key ID: F456F05FBF825330
2 changed files with 10 additions and 7 deletions

View file

@ -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;

View file

@ -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;
}