Embedded Artistry Framework
Embedded Systems C++ Framework
Macros | Functions
memchr.c File Reference
#include <limits.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for memchr.c:

Macros

#define SS   (sizeof(size_t))
 
#define ALIGN   (sizeof(size_t) - 1)
 
#define ONES   ((size_t)-1 / UCHAR_MAX)
 
#define HIGHS   (ONES * (UCHAR_MAX / 2 + 1))
 
#define HASZERO(x)   ((x)-ONES & ~(x)&HIGHS)
 

Functions

void * memchr (const void *src, int c, size_t n)
 Finds the first occurrence of c in the initial n characters of the object pointed to by s. More...
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN   (sizeof(size_t) - 1)

◆ HASZERO

#define HASZERO (   x)    ((x)-ONES & ~(x)&HIGHS)

◆ HIGHS

#define HIGHS   (ONES * (UCHAR_MAX / 2 + 1))

◆ ONES

#define ONES   ((size_t)-1 / UCHAR_MAX)

◆ SS

#define SS   (sizeof(size_t))

Function Documentation

◆ memchr()

void* memchr ( const void *  s,
int  c,
size_t  n 
)

Finds the first occurrence of c in the initial n characters of the object pointed to by s.

Finds the first occurrence of c (after conversion to unsigned char as if by (unsigned char)c ) in the initial n characters (each interpreted as unsigned char) of the object pointed to by s.

The behavior is undefined if access occurs beyond the end of the array (s) searched. The behavior is undefined if s is a null pointer.

Parameters
spointer to the object to be examined
ccharacter to search for
nmax number of characters to examine
Returns
a copy of dest

References __attribute__, ALIGN, HASZERO, k, n, ONES, s, SS, and w.

Referenced by memmem().

Here is the caller graph for this function: