memcmp
Section: C Library Functions (3)
Updated: 2026-02-08
Index
JM Home Page
roff page
名前
memcmp - メモリー領域を比較する
ライブラリ
標準 C ライブラリ (libc,~-lc)
書式
#include <string.h>
int memcmp(size_t n;
const void s1[n], const void s2[n], size_t n);
説明
The memcmp() function compares the first n bytes (each interpreted as
unsigned char) of the memory areas s1 and s2.
返り値
memcmp() 関数は、s1 の最初の n バイトが s2 の最初の n バイトよりも
小さいか、同じか、あるいは大きいかによってそれぞれ、負の整数、0、 正の整数を返す。
0 でない値の場合、 s1 と s2 で値が異なった最初のバイトの値の差で符号は決定される (バイトは unsigned char
で解釈される)。
n が 0 の場合、返り値は 0 となる。
属性
この節で使用されている用語の説明については、 attributes(7) を参照。
| インターフェース | 属性 | 値
|
|
memcmp()
| Thread safety | MT-Safe
|
標準規格
C11, POSIX.1-2008.
歴史
POSIX.1-2001, C89, SVr4, 4.3BSD.
警告
Do not use memcmp() to compare confidential data, such as cryptographic
secrets, because the CPU time required for the comparison depends on the
contents of the addresses compared, this function is subject to timing-based
side-channel attacks. In such cases, a function that performs comparisons
in deterministic time, depending only on n (the quantity of bytes
compared) is required. Some operating systems provide such a function
(e.g., NetBSD's consttime_memequal()), but no such function is specified
in POSIX. On Linux, you may need to implement such a function yourself.
関連項目
bstring(3), strcasecmp(3), strcmp(3), strcoll(3),
strncasecmp(3), strncmp(3), wmemcmp(3)
Index
- 名前
-
- ライブラリ
-
- 書式
-
- 説明
-
- 返り値
-
- 属性
-
- 標準規格
-
- 歴史
-
- 警告
-
- 関連項目
-
This document was created by
man2html,
using the manual pages.