mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Added atoi(3).
This commit is contained in:
parent
ae599b6d67
commit
33c0a9586e
3 changed files with 16 additions and 0 deletions
|
@ -45,6 +45,7 @@ typedef int div_t, ldiv_t, lldiv_t;
|
|||
|
||||
/* TODO: WEXITSTATUS, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED is missing here */
|
||||
|
||||
int atoi(const char*);
|
||||
void exit(int);
|
||||
void _Exit(int status);
|
||||
void free(void*);
|
||||
|
|
|
@ -39,6 +39,7 @@ namespace Maxsi
|
|||
int Compare(const char* A, const char* B);
|
||||
int CompareN(const char* A, const char* B, size_t MaxLength);
|
||||
int StartsWith(const char* Haystack, const char* Needle);
|
||||
int ToInt(const char* str);
|
||||
|
||||
int ConvertUInt8T(uint8_t num, char* dest);
|
||||
int ConvertUInt16(uint16_t num, char* dest);
|
||||
|
|
|
@ -90,6 +90,20 @@ namespace Maxsi
|
|||
return Result;
|
||||
}
|
||||
|
||||
DUAL_FUNCTION(int, atoi, ToInt, (const char* str))
|
||||
{
|
||||
bool negative = ( *str == '-' );
|
||||
if ( negative ) { str++; }
|
||||
int result = 0;
|
||||
int c;
|
||||
while ( (c = *str++) != 0 )
|
||||
{
|
||||
if ( c < '0' || '9' < c ) { return result; }
|
||||
result = result * 10 + c - '0';
|
||||
}
|
||||
return (negative) ? -result : result;
|
||||
}
|
||||
|
||||
#if 0
|
||||
char* Combine(size_t NumParameters, ...)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue