The <mem.h> header file


  
This header file contains the following functions:
_memset             memchr              memcmp              memcpy
memmove             memset
and the following constants and predefined types:
NULL                size_t

Functions


void *memcpy (void *dest, const void *src, unsigned long len);

Copies a block of len bytes from src to dest.

memcpy copies a block of len bytes from src to dest. If src and dest overlap, the memcpy is ill-behaved (in such case, use memmove instead). memcpy returns dest.

void *memchr (const void *str, short c, unsigned long len);

Searches the first len bytes of array str for character c.

memchr searches the first len bytes of the block pointed to by str for character c. On success, memchr returns a pointer to the first occurrence of c in str. Otherwise, it returns NULL.

void *memmove (void *dest, const void *src, unsigned long len);

Copies a block of len bytes from src to dest, with possibility of overlaping of source and destination block.

memmove copies a block of len bytes from src to dest. Even when the source and destination blocks overlap, bytes in the overlapping locations are copied correctly (in opposite to memcpy). memmove returns dest.

short memcmp (const void *s1, const void *s2, unsigned long len);

Compares two blocks, s1 and s2, for a length of exactly len bytes.

memcmp compares the first len bytes of the blocks s1 and s2 as unsigned chars. Since it compares bytes as unsigned chars, memcmp returns a value For example, memcmp("\xFF","\x7F",1) returns a value greater than 0. More precise, the exact return value is the result of subtracting the first pair of values that differ in the two blocks being compared based on them being signed chars.

NOTE: This routine is declared as "short" although ANSI standard proposes "long". It is important, because TIOS memcmp routine puts a garbage in higher half of D0 register!

void *memset (void *buffer, short c, unsigned long num);

Sets num bytes of buffer to byte c.

memset sets the first num bytes of the array buffer to the character c. memset is faster than _memset, because it sets a memory in a 4-byte chunks as long as possible. memset returns buffer.

void *_memset (void *buffer, short c, unsigned long num);

Sets num bytes of buffer to byte c.

_memset is a slower (byte-by-byte) variant of memset.


Constants and predefined types


type size_t

size_t is a type proposed in ANSI C for defining size of strings and memory blocks. It is defined here as
typedef unsigned long size_t;

const NULL

NULL is a null-pointer value, defined as (void *) 0.

Return to the main index