]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/memcmp.3
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man3 / memcmp.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
4.\"
5.\" References consulted:
6.\" Linux libc source code
7.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
8.\" 386BSD man pages
9.\" Modified Sat Jul 24 18:55:27 1993 by Rik Faith (faith@cs.unc.edu)
45186a5d 10.TH MEMCMP 3 2021-03-22 "Linux man-pages (unreleased)"
fea681da
MK
11.SH NAME
12memcmp \- compare memory areas
2f2d3b46
AC
13.SH LIBRARY
14Standard C library
8fc3b2cf 15.RI ( libc ", " \-lc )
fea681da
MK
16.SH SYNOPSIS
17.nf
18.B #include <string.h>
68e4db0a 19.PP
fea681da
MK
20.BI "int memcmp(const void *" s1 ", const void *" s2 ", size_t " n );
21.fi
22.SH DESCRIPTION
60a90ecd
MK
23The
24.BR memcmp ()
4c4d76cd
MK
25function compares the first \fIn\fP bytes (each interpreted as
26.IR "unsigned char" )
27of the memory areas \fIs1\fP and \fIs2\fP.
47297adb 28.SH RETURN VALUE
60a90ecd
MK
29The
30.BR memcmp ()
31function returns an integer less than, equal to, or
c13182ef 32greater than zero if the first \fIn\fP bytes of \fIs1\fP is found,
fea681da
MK
33respectively, to be less than, to match, or be greater than the first
34\fIn\fP bytes of \fIs2\fP.
847e0d88 35.PP
3b5b9fd8
MK
36For a nonzero return value, the sign is determined by the sign of
37the difference between the first pair of bytes (interpreted as
38.IR "unsigned char" )
39that differ in
40.I s1
41and
42.IR s2 .
847e0d88 43.PP
7f139a45
MH
44If
45.I n
46is zero, the return value is zero.
c4313c2c 47.SH ATTRIBUTES
d2c36c04
PH
48For an explanation of the terms used in this section, see
49.BR attributes (7).
c466875e
MK
50.ad l
51.nh
d2c36c04
PH
52.TS
53allbox;
c466875e 54lbx lb lb
d2c36c04
PH
55l l l.
56Interface Attribute Value
57T{
c4313c2c 58.BR memcmp ()
d2c36c04
PH
59T} Thread safety MT-Safe
60.TE
c466875e
MK
61.hy
62.ad
63.sp 1
3113c7f3 64.SH STANDARDS
62accc7c 65POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
f70fe9d7 66.SH NOTES
f70fe9d7
MH
67Do not use
68.BR memcmp ()
69to compare security critical data, such as cryptographic secrets,
03417139 70because the required CPU time depends on the number of equal bytes.
8b201be5
MK
71Instead, a function that performs comparisons in constant time is required.
72Some operating systems provide such a function (e.g., NetBSD's
8d476c39 73.BR consttime_memequal ()),
8b201be5
MK
74but no such function is specified in POSIX.
75On Linux, it may be necessary to implement such a function oneself.
47297adb 76.SH SEE ALSO
fea681da 77.BR bcmp (3),
879091c9 78.BR bstring (3),
fea681da
MK
79.BR strcasecmp (3),
80.BR strcmp (3),
81.BR strcoll (3),
82.BR strncasecmp (3),
83.BR strncmp (3),
84.BR wmemcmp (3)