Added atoi(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2011-11-09 23:48:26 +01:00
parent ae599b6d67
commit 33c0a9586e
3 changed files with 16 additions and 0 deletions

View File

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

View File

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

View File

@ -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, ...)
{