1
0
Fork 0
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:
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, ...)
{