mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
up
This commit is contained in:
parent
08d08539d8
commit
3fc80a9a28
@ -23,17 +23,21 @@
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <libc.h>
|
||||
#include <lib/buf.h>
|
||||
|
||||
long strtol(const char *str, char **endp, int base) {
|
||||
char c;
|
||||
ulong n;
|
||||
bool neg = 0;
|
||||
const char *save, *start = str;
|
||||
|
||||
assert(str != NULL);
|
||||
|
||||
char c = *str;
|
||||
|
||||
// Ignore leading spaces
|
||||
do {
|
||||
while (isspace(c)) {
|
||||
c = *str++;
|
||||
} while (isspace(c));
|
||||
}
|
||||
|
||||
// Accept any +/-'s, whatever the base
|
||||
// In particular we accept things like "-0xF"
|
||||
@ -100,13 +104,19 @@ long strtol(const char *str, char **endp, int base) {
|
||||
// Made from the code above by removing "neg"
|
||||
//
|
||||
ulong strtoul(const char *str, char **endp, int base) {
|
||||
char c;
|
||||
ulong n;
|
||||
const char *save, *start = str;
|
||||
|
||||
do {
|
||||
assert(str != NULL);
|
||||
|
||||
char c = *str;
|
||||
|
||||
while (isspace(c)) {
|
||||
c = *str++;
|
||||
}
|
||||
|
||||
if (c == '+')
|
||||
c = *str++;
|
||||
} while (isspace(c));
|
||||
|
||||
if (c == '0') {
|
||||
c = *str++;
|
||||
@ -142,10 +152,9 @@ ulong strtoul(const char *str, char **endp, int base) {
|
||||
n = (n * base) + c;
|
||||
}
|
||||
}
|
||||
|
||||
if (endp != NULL)
|
||||
*endp = (char *)(str == save ? start : str);
|
||||
|
||||
return n;
|
||||
return (long)n;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user