add zend_atol() and use it instead of zend_atoi() where applicable

This commit is contained in:
Antony Dovgal 2008-03-19 12:40:20 +00:00
parent 4ce259fc1a
commit 500e17c5c1
3 changed files with 31 additions and 2 deletions

View File

@ -557,7 +557,7 @@ ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
p = (long *) (base+(size_t) mh_arg1);
*p = zend_atoi(new_value, new_value_length);
*p = zend_atol(new_value, new_value_length);
return SUCCESS;
}
/* }}} */
@ -573,7 +573,7 @@ ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
base = (char *) ts_resource(*((int *) mh_arg2));
#endif
tmp = zend_atoi(new_value, new_value_length);
tmp = zend_atol(new_value, new_value_length);
if (tmp < 0) {
return FAILURE;
}

View File

@ -75,6 +75,34 @@ ZEND_API int zend_atoi(const char *str, int str_len) /* {{{ */
}
/* }}} */
ZEND_API long zend_atol(const char *str, int str_len) /* {{{ */
{
long retval;
if (!str_len) {
str_len = strlen(str);
}
retval = strtol(str, NULL, 0);
if (str_len>0) {
switch (str[str_len-1]) {
case 'g':
case 'G':
retval *= 1024;
/* break intentionally missing */
case 'm':
case 'M':
retval *= 1024;
/* break intentionally missing */
case 'k':
case 'K':
retval *= 1024;
break;
}
}
return retval;
}
/* }}} */
ZEND_API double zend_string_to_double(const char *number, zend_uint length) /* {{{ */
{
double divisor = 10.0;

View File

@ -336,6 +336,7 @@ ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2 TSRMLS_DC);
ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2 TSRMLS_DC);
ZEND_API int zend_atoi(const char *str, int str_len);
ZEND_API int zend_atol(const char *str, int str_len);
ZEND_API void zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC);
END_EXTERN_C()