Add strtol native (bug 3233, r=joropito)
Former-commit-id: 9508f9f86db99e93de1819f585c741396d8e4c30
This commit is contained in:
@ -341,6 +341,28 @@ static cell AMX_NATIVE_CALL strtonum(AMX *amx, cell *params) /* 1 param */
|
||||
return atoi(get_amxstring(amx, params[1], 0, iLen));
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL amx_strtol(AMX *amx, cell *params) /* 3 param */
|
||||
{
|
||||
int len;
|
||||
int base = params[3];
|
||||
|
||||
if( base != 0 && ( base < 2 || base > 36 ) )
|
||||
base = 0;
|
||||
|
||||
char *pString = get_amxstring( amx, params[1], 0, len );
|
||||
cell *endPos = get_amxaddr( amx, params[2] );
|
||||
|
||||
*endPos = -1;
|
||||
|
||||
char *pEnd = NULL;
|
||||
long result = strtol( pString, &pEnd, base );
|
||||
|
||||
if( pEnd != NULL && pString != pEnd )
|
||||
*endPos = pEnd - pString;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL numtostr(AMX *amx, cell *params) /* 3 param */
|
||||
{
|
||||
char szTemp[32];
|
||||
@ -1130,6 +1152,7 @@ AMX_NATIVE_INFO string_Natives[] =
|
||||
{"strtoupper", strtoupper},
|
||||
{"str_to_num", strtonum},
|
||||
{"strtonum", strtonum},
|
||||
{"strtol", amx_strtol},
|
||||
{"trim", amx_trim},
|
||||
{"ucfirst", amx_ucfirst},
|
||||
{"strtok", amx_strtok},
|
||||
|
Reference in New Issue
Block a user