]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" References consulted: | |
26 | .\" Linux libc source code | |
27 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
28 | .\" 386BSD man pages | |
29 | .\" Modified Sat Jul 24 18:55:27 1993 by Rik Faith (faith@cs.unc.edu) | |
4b8c67d9 | 30 | .TH MEMCMP 3 2017-09-15 "" "Linux Programmer's Manual" |
fea681da MK |
31 | .SH NAME |
32 | memcmp \- compare memory areas | |
33 | .SH SYNOPSIS | |
34 | .nf | |
35 | .B #include <string.h> | |
68e4db0a | 36 | .PP |
fea681da MK |
37 | .BI "int memcmp(const void *" s1 ", const void *" s2 ", size_t " n ); |
38 | .fi | |
39 | .SH DESCRIPTION | |
60a90ecd MK |
40 | The |
41 | .BR memcmp () | |
4c4d76cd MK |
42 | function compares the first \fIn\fP bytes (each interpreted as |
43 | .IR "unsigned char" ) | |
44 | of the memory areas \fIs1\fP and \fIs2\fP. | |
47297adb | 45 | .SH RETURN VALUE |
60a90ecd MK |
46 | The |
47 | .BR memcmp () | |
48 | function returns an integer less than, equal to, or | |
c13182ef | 49 | greater than zero if the first \fIn\fP bytes of \fIs1\fP is found, |
fea681da MK |
50 | respectively, to be less than, to match, or be greater than the first |
51 | \fIn\fP bytes of \fIs2\fP. | |
847e0d88 | 52 | .PP |
3b5b9fd8 MK |
53 | For a nonzero return value, the sign is determined by the sign of |
54 | the difference between the first pair of bytes (interpreted as | |
55 | .IR "unsigned char" ) | |
56 | that differ in | |
57 | .I s1 | |
58 | and | |
59 | .IR s2 . | |
847e0d88 | 60 | .PP |
7f139a45 MH |
61 | If |
62 | .I n | |
63 | is zero, the return value is zero. | |
c4313c2c | 64 | .SH ATTRIBUTES |
d2c36c04 PH |
65 | For an explanation of the terms used in this section, see |
66 | .BR attributes (7). | |
67 | .TS | |
68 | allbox; | |
69 | lb lb lb | |
70 | l l l. | |
71 | Interface Attribute Value | |
72 | T{ | |
c4313c2c | 73 | .BR memcmp () |
d2c36c04 PH |
74 | T} Thread safety MT-Safe |
75 | .TE | |
47297adb | 76 | .SH CONFORMING TO |
62accc7c | 77 | POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. |
f70fe9d7 MH |
78 | .SH NOTES |
79 | .PP | |
80 | Do not use | |
81 | .BR memcmp () | |
82 | to compare security critical data, such as cryptographic secrets, | |
03417139 | 83 | because the required CPU time depends on the number of equal bytes. |
8b201be5 MK |
84 | Instead, a function that performs comparisons in constant time is required. |
85 | Some operating systems provide such a function (e.g., NetBSD's | |
8d476c39 | 86 | .BR consttime_memequal ()), |
8b201be5 MK |
87 | but no such function is specified in POSIX. |
88 | On Linux, it may be necessary to implement such a function oneself. | |
47297adb | 89 | .SH SEE ALSO |
fea681da | 90 | .BR bcmp (3), |
879091c9 | 91 | .BR bstring (3), |
fea681da MK |
92 | .BR strcasecmp (3), |
93 | .BR strcmp (3), | |
94 | .BR strcoll (3), | |
95 | .BR strncasecmp (3), | |
96 | .BR strncmp (3), | |
97 | .BR wmemcmp (3) |