tiny_stdlib.h File Reference

Tiny portable implementations of standard library functions. More...

#include <stddef.h>

Functions

void * memset (void *ptr, int value, size_t num)
 Fill block of memory. More...
 
int memcmp (const void *ptr1, const void *ptr2, size_t num)
 Compare two blocks of memory. More...
 

Detailed Description

Tiny portable implementations of standard library functions.

Function Documentation

◆ memcmp()

int memcmp ( const void *  ptr1,
const void *  ptr2,
size_t  num 
)

Compare two blocks of memory.

Compares the first num bytes of the block of memory pointed by ptr1 to the first num bytes pointed by ptr2, returning zero if they all match or a value different from zero representing which is greater if they do not.

Notice that, unlike strcmp, the function does not stop comparing after finding a null character.

Parameters
ptr1Pointer to block of memory.
ptr2Pointer to block of memory.
numNumber of bytes to compare.
Returns
an integral value indicating the relationship between the content of the memory blocks:
Return values
<0the first byte that does not match in both memory blocks has a lower value in ptr1 than in ptr2 (if evaluated as unsigned char values)
0the contents of both memory blocks are equal
>0the first byte that does not match in both memory blocks has a greater value in ptr1 than in ptr2 (if evaluated as unsigned char values)

◆ memset()

void* memset ( void *  ptr,
int  value,
size_t  num 
)

Fill block of memory.

Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char)

Parameters
ptrPointer to the block of memory to fill.
valueValue to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.
numNumber of bytes to be set to the value. size_t is an unsigned integral type.
Returns
ptr is returned.