插件窝 干货文章 php strncmp函数原型源码分析

php strncmp函数原型源码分析

class Zend len strncmp 502    来源:    2024-10-17

strncmp

函数原型

源码分析 版本PHP 5.6.40

1、Zend/zend_builtin_functions.c (内置函数)

ZEND_FUNCTION(strncmp)
{
    char *s1, *s2;
    int s1_len, s2_len;
    long len;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &s1, &s1_len, &s2, &s2_len, &len) == FAILURE) {
        return;
    }
    if (len < 0) {
        zend_error(E_WARNING, "Length must be greater than or equal to 0");
        RETURN_FALSE;
    }
    RETURN_LONG(zend_binary_strncmp(s1, s1_len, s2, s2_len, len));
}

2、Zend/zend_operators.c

ZEND_API int zend_binary_strncmp(const char *s1, uint len1, const char *s2, uint len2, uint length) /* {{{ */
{
    int retval;
    if (s1 == s2) {
        return 0;
    }
    retval = memcmp(s1, s2, MIN(length, MIN(len1, len2)));
    if (!retval) {
        return (MIN(length, len1) - MIN(length, len2));
    } else {
        return retval;
    }
}

3、memcmp 用法

以上就是php strncmp函数原型源码分析的详细内容,更多关于php strncmp源码分析的资料请关注插件窝其它相关文章!