#include <stdlib.h>
void * memchr (const void *block, int c, size_t size);
int memcmp (const void *a1, const void *a2, size_t size);
void * memcpy (void *restrict to, const void *restrict from, size_t size);
void * memmove (void *to, const void *from, size_t size);
void * memset (void *block, int c, size_t size);
1、memchr
void * memchr (const void *block, int c, size_t size);
Description:
This function finds the first occurrence of the byte c (converted to an unsigned char) in the initial size
bytes of the object beginning at block. The return value is a pointer to the located byte, or a null
pointer if no match was found.
2、memcmp
int memcmp (const void *a1, const void *a2, size_t size);
Description:
The function memcmp compares the size bytes of memory beginning at a1 against the size bytes of
memory beginning at a2. The value returned has the same sign as the difference between the first
differing pair of bytes (interpreted as unsigned char objects, then promoted to int).
If the contents of the two blocks are equal, memcmp returns 0.
3、memcpy
void * memcpy (void *restrict to, const void *restrict from, size_t size);
Description:
The memcpy function copies size bytes from the object beginning at from into the object beginning
at to. The behavior of this function is undefined if the two arrays to and from overlap; use memmove
instead if overlapping is possible.
The value returned by memcpy is the value of to.
Here is an example of how you might use memcpy to copy the contents of an array:
struct foo *oldarray, *newarray;
int arraysize;
...
memcpy (new, old, arraysize * sizeof (struct foo));
e.g.
/*拷贝数组*/
unsigned char bufA[BUF_LEN];
unsigned char bufB[BUF_LEN];
memcpy(bufA, bufB, BUF_LEN - 1); /* 预留最后一位给空字符'\0' */
4、memmove
void * memmove (void *to, const void *from, size_t size);
Description:
memmove copies the size bytes at from into the size bytes at to, even if those two blocks of space
overlap. In the case of overlap, memmove is careful to copy the original values of the bytes in the
block at from, including those bytes which also belong to the block at to.
The value returned by memmove is the value of to.
5、memset
void * memset (void *block, int c, size_t size);
Description:
This function copies the value of c (converted to an unsigned char) into each of the first size bytes of
the object beginning at block. It returns the value of block.
e.g.
/*清空数组*/
unsigned char buff[BUFF_LEN];
memset(buff, 0, BUFF_LEN);
/*清空结构体*/
struct IP_Packet ip_pkt;
memset(&ip_pkt, 0, sizeof(IP_Packet));