Skip to content

Commit 45b5331

Browse files
committed
Add memcmp implementation
1 parent eee1b99 commit 45b5331

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ jobs:
226226
set -x
227227
./buildconf --force
228228
./configure \
229-
CFLAGS="-fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset" \
229+
CFLAGS="-fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset -fno-builtin-memcmp" \
230230
--disable-debug \
231231
--enable-mbstring \
232232
--enable-opcache \

Zend/zend_alloc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,6 +3216,23 @@ void *memset(void *s, int c, size_t n)
32163216

32173217
return s;
32183218
}
3219+
int memcmp(const void *s1, const void *s2, size_t n)
3220+
{
3221+
if (s1 == s2) {
3222+
return 0;
3223+
}
3224+
3225+
unsigned char *p = (unsigned char *)s1;
3226+
unsigned char *q = (unsigned char *)s2;
3227+
while (n-- != 0) {
3228+
if (*p != *q) {
3229+
return (*p > *q) ? 1 : -1;
3230+
}
3231+
p++;
3232+
q++;
3233+
}
3234+
return 0;
3235+
}
32193236
# if defined(__GNUC__) && !defined(__clang__)
32203237
# pragma GCC pop_options
32213238
# endif

0 commit comments

Comments
 (0)