]> granicus.if.org Git - php/commitdiff
Patches from Walter for strncmp() stuff.
authorAndrei Zmievski <andrei@php.net>
Tue, 8 Feb 2000 17:19:43 +0000 (17:19 +0000)
committerAndrei Zmievski <andrei@php.net>
Tue, 8 Feb 2000 17:19:43 +0000 (17:19 +0000)
Zend/zend_builtin_functions.c
Zend/zend_operators.c
Zend/zend_operators.h

index 15a875e0e52b977b1fdc1683b74196c2878689b5..102ab24df8b546fafd06ff7662cb6ed98f32c439 100644 (file)
@@ -31,6 +31,7 @@ static ZEND_FUNCTION(func_get_arg);
 static ZEND_FUNCTION(func_get_args);
 static ZEND_FUNCTION(strlen);
 static ZEND_FUNCTION(strcmp);
+static ZEND_FUNCTION(strncmp);
 static ZEND_FUNCTION(strcasecmp);
 static ZEND_FUNCTION(each);
 static ZEND_FUNCTION(error_reporting);
@@ -55,6 +56,7 @@ static zend_function_entry builtin_functions[] = {
        ZEND_FE(func_get_args,          NULL)
        ZEND_FE(strlen,                         NULL)
        ZEND_FE(strcmp,                         NULL)
+       ZEND_FE(strncmp,                        NULL)
        ZEND_FE(strcasecmp,                     NULL)
        ZEND_FE(each,                           first_arg_force_ref)
        ZEND_FE(error_reporting,        NULL)
@@ -197,6 +199,22 @@ ZEND_FUNCTION(strcmp)
 }
 /* }}} */
 
+/* {{{ proto int strncmp(string str1, string str2, int len)
+   Binary safe string comparison */
+ZEND_FUNCTION(strncmp)
+{
+       zval **s1, **s2, **s3;
+       
+       if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &s1, &s2, &s3) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+       convert_to_string_ex(s1);
+       convert_to_string_ex(s2);
+       convert_to_long_ex(s3);
+       RETURN_LONG(zend_binary_zval_strncmp(*s1,*s2,*s3));
+}
+/* }}} */
+
 /* {{{ proto int strcasecmp(string str1, string str2)
    Binary safe case-insensitive string comparison */
 ZEND_FUNCTION(strcasecmp)
index 7bbf4ccc3f5ceb0b62b2f674d925a28674c58cdc..b8de6d3562eaa42547f9ab2294df206c270afd58 100644 (file)
@@ -1230,6 +1230,18 @@ ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2)
        }
 }
 
+ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, int length)
+{
+       int retval;
+       
+       retval = memcmp(s1, s2, MIN(length, MIN(len1, len2)));
+       if (!retval) {
+               return (len1 - len2);
+       } else {
+               return retval;
+       }
+}
+
 
 ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2)
 {
@@ -1256,6 +1268,11 @@ ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2)
        return zend_binary_strcmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len);
 }
 
+ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3)
+{
+       return zend_binary_strncmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len, s3->value.lval);
+}
+
 
 ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2)
 {
@@ -1263,7 +1280,6 @@ ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2)
 }
 
 
-
 ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2)
 {
        int ret1,ret2;
index 82c4f7cbd04b7c89260a71ba094a729ec27cc1b6..e106f1481bdf2065a658b4056466b3bce440d622 100644 (file)
@@ -70,6 +70,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2);
 
 ZEND_API void zend_str_tolower(char *str, unsigned int length);
 ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
+ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
 ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
 ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
 ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);