welibc
A clear, secure, and well documented standard C library
Functions
memcmp.c File Reference

Defines the memcmp function. More...

#include <string.h>
Include dependency graph for memcmp.c:

Go to the source code of this file.

Functions

int memcmp (const void *s1, const void *s2, size_t n)
 Compares the first n characters of s1 and s2. More...
 

Detailed Description

Defines the memcmp function.

Definition in file memcmp.c.

Function Documentation

◆ memcmp()

int memcmp ( const void *  s1,
const void *  s2,
size_t  n 
)

Compares the first n characters of s1 and s2.

Parameters
*s1The first object to be compared
*s2The second object to be compared
nThe number of characters to compare

The memcmp function compares the first n characters of the object pointed to by s1 to the first n characters of the object pointed to by s2.

Note
The contents of "holes" used as padding for purposes of alignment within structure objects are indeterminate. Strings shorter than their allocated space and unions may also cause problems in comparison.
If n is 0 then valid objects are considered equal
The returned value will never be greater than UCHAR_MAX and never less than CHAR_MIN
If the comparison will cause a memory read that wraps then the comparison will not take place
Returns
Integer indicating if s1 is greater than, equal to, or less than s2
Return values
>0s1 is greater than s2 or no comparison could be made
0s1 is equal to s2
<0s1 is less than s2

Definition at line 68 of file memcmp.c.

Referenced by strcmp(), and strncmp().

Here is the caller graph for this function: